modularity : Closures and function scopes (JS without block-level scope ES6) Construction module
1 varman=function(){2 varAge=12;3 return {4GetYear:function(){5 returnAge ;6 },7Setyear:function(n) {8Age=N;9 }Ten } One } A - varPeter=Man (); -document.write (Peter.getyear ());// A thePeter.setyear (20); -document.write (Peter.getyear ());// - -document.write (Peter.age);//undefined property Private can only be accessed through the interface
no new, create object. Restrict access to the properties of this object (only by means of this object)
1, no new, create object.
2, restrict the access to this object's properties (this object's properties can only be obtained by means of this object )
Chained programming:
1 varman=function(){2 varAge=12;3 return {4GetYear:function(){5 alert (age);6 return This;7 },8Setyear:function(n) {9Age=N;Ten return This; One } A } - } - the varPeter=Man (); -Peter.getyear (). Setyear ((). GetYear ();//Cascade
1 No new, create object. 2 Each method, except the action, will return this,this to this {} Nameless JSON object. There are both actions and return objects. Reach Chain Type
1, no new, create object.
2, each method, except the action, will return This,this point to this {} Nameless JSON object.
both actions and objects are returned . reach chain Type
JavaScript series: Modular and chained programming