Skip to content

Commit

Permalink
[v1.0.3] added setter demo
Browse files Browse the repository at this point in the history
  • Loading branch information
williamli committed May 26, 2015
1 parent c3862b5 commit 3b0dc39
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
19degrees:[email protected].1
19degrees:[email protected].3
[email protected]
[email protected]
[email protected]
Expand All @@ -8,7 +8,7 @@ [email protected]
[email protected]
[email protected]
[email protected]
local-test:19degrees:[email protected].1
local-test:19degrees:[email protected].3
[email protected]
[email protected]
[email protected]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ It can only be access by functions (both public and private) defined in the same

### Best Practice
Create private variables using var inside Object declaration like `_private`.
Access private variables via getter and setter like `_best_practice_private_function`.
Access private variables via getter and setter like `_best_practice_getter_for_private_variable` and `_best_practice_setter_for_private_variable`.
Create pubilc functions with `prototype` like `best_practice_public_function`.
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: '19degrees:scope-permission-demo',
version: '1.0.1',
version: '1.0.3',
// Brief, one-line summary of the package.
summary: 'An in-depth look into scoping and permissions of Meteor.',
// URL to the Git repository containing the source code for this package.
Expand Down
10 changes: 9 additions & 1 deletion scope-permission-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ScopePermissionDemo = function(aString) {
return _private_variable;
}

_best_practice_setter_for_private_variable = function(new_private) {
_private_variable = new_private;
}

self.instance_function_by_self = function() {
console.log('this is a public instance function created by "self"');

Expand Down Expand Up @@ -136,7 +140,11 @@ ScopePermissionDemo.prototype.instance_function_by_prototype = function() {
}

ScopePermissionDemo.prototype.best_practice_public_function = function() {
console.log('access to _private variable by calling a private getter:',_best_practice_getter_for_private_variable());
var current_private = _best_practice_getter_for_private_variable();
console.log('access to _private variable by calling a private getter:',current_private);
console.log('updating _private to new vaule with _best_practice_setter_for_private_variable...');
_best_practice_setter_for_private_variable(current_private+" updated!");
console.log('_private:',_best_practice_getter_for_private_variable());
}

ScopePermissionDemo.static_function = function() {
Expand Down

0 comments on commit 3b0dc39

Please sign in to comment.