diff --git a/.versions b/.versions new file mode 100644 index 0000000..5e352f2 --- /dev/null +++ b/.versions @@ -0,0 +1,21 @@ +19degrees:scope-permission-demo@1.0.1 +base64@1.0.3 +binary-heap@1.0.3 +callback-hook@1.0.3 +check@1.0.5 +ddp@1.1.0 +ejson@1.0.6 +geojson-utils@1.0.3 +id-map@1.0.3 +json@1.0.3 +local-test:19degrees:scope-permission-demo@1.0.1 +logging@1.0.7 +meteor@1.1.6 +minimongo@1.0.8 +mongo@1.1.0 +ordered-dict@1.0.3 +random@1.0.3 +retry@1.0.3 +tinytest@1.0.5 +tracker@1.0.7 +underscore@1.0.3 diff --git a/README.md b/README.md index f93a2ca..afd694b 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,9 @@ Private instance functions defrined by using `var` in Object declaration. ```javascript var _private_function_by_var_function = function() {...} ``` -It can only be access by functions (both public and private) defined in the same Object declaration but not by public functions created using *prototypes*. \ No newline at end of file +It can only be access by functions (both public and private) defined in the same Object declaration but not by public functions created using *prototypes*. + +### Best Practice +Create private variables using var inside Object declaration like `_private`. +Access private variables via getter and setter like `_best_practice_private_function`. +Create pubilc functions with `prototype` like `best_practice_public_function`. \ No newline at end of file diff --git a/package.js b/package.js index 700e6e2..e92eb21 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: '19degrees:scope-permission-demo', - version: '1.0.0', + version: '1.0.1', // 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. diff --git a/scope-permission-demo.js b/scope-permission-demo.js index 46a8444..6b90093 100644 --- a/scope-permission-demo.js +++ b/scope-permission-demo.js @@ -24,7 +24,14 @@ ScopePermissionDemo = function(aString) { } + + _best_practice_private_function = function() { + console.log('this is the best way to make a private function accessible by prototype functions'); + } + _best_practice_getter_for_private_variable = function() { + return _private_variable; + } self.instance_function_by_self = function() { console.log('this is a public instance function created by "self"'); @@ -128,6 +135,10 @@ 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()); +} + ScopePermissionDemo.static_function = function() { console.log('this is a public static function');