标签:pre this 模块 on() fun fir error return for
1.原始模式
function a(){...} function b(){...}
2.对象模式
var moduler = new object({ _count:0, m1:function(){...}, m2:function(){...} });
这种写法会暴露模块化成员,内部状态可以被改变。
moduler._count =5;
3.模块化模式
var moduler = (function(){ var _count=0; var m1 = function(){ ...} var m2 = function(){ ...} return {m1:m1,
m2:m2
}; })();
var p3 = (function(){
var firstname = "a";
function changeFirstName(name){
this.firstname = name;
}
function getFirstName(){
return this.firstname;
}
return {
getFirstName:getFirstName,
changeFirstName:changeFirstName
}
})();
p3.changeFirstName("p3 first");
console.log(p3.getFirstName());
//console.log(p3.firstname()); //error , no access for p3.firstname
标签:pre this 模块 on() fun fir error return for
原文地址:https://www.cnblogs.com/starwar/p/9336718.html