@@ -57,7 +57,7 @@ function myFunction(){
57
57
* any variables part of constructor closure are not visible outside of it
58
58
59
59
``` js
60
- function Person (){
60
+ function Person (){
61
61
var secret = ' hey' ;
62
62
return {
63
63
doIt : function (){
@@ -78,3 +78,35 @@ me.doIt(); //does it
78
78
* internal arrays/objects are still modifiable via reference
79
79
* make sure you return a new object with only the properties needed by caller
80
80
* or copy your objects/arrays (with utility methods)
81
+
82
+ ## private properties on prototype
83
+
84
+ * properties are re-created every time an object is initialized
85
+ * shared properties of prototype can also be made private with the same pattern
86
+
87
+ ``` js
88
+ Person .prototype = (function (){
89
+ // all person sharing the same secret
90
+ var secret = ' hey' ;
91
+ return {
92
+ doIt : function (){
93
+ // can see secret
94
+ }
95
+ }
96
+ }());
97
+ ```
98
+
99
+ ## revealing module pattern
100
+
101
+ * revealing private methods by assigning them to properties of the returned object
102
+ * can name the property differently to the internal function
103
+ * can expose internal function under more than one names
104
+
105
+ ``` js
106
+ Person .prototype = (function (){
107
+ function sayHello () {}
108
+ return {
109
+ greeting: sayHello
110
+ }
111
+ }());
112
+ ```
0 commit comments