传统的是这样
对象的写法这样var current = null;
var labels = {
'home':'home',
'articles':'articles',
'contact':'contact'
};
function init(){
};
function show(){
current = 1;
};
function hide(){
show();
};
模块化的是这样demo = {
current:null,
labels:{
'home':'home',
'articles':'articles',
'contact':'contact'
},
init:function(){
},
show:function(){
demo.current = 1;
},
hide:function(){
demo.show();
}
}
优化后是这样module = function(){
var labels = {
'home':'home',
'articles':'articles',
'contact':'contact'
};
return {
current:null,
init:function(){
},
show:function(){
module.current = 1;
},
hide:function(){
module.show();
}
}
}();
国外的月亮是圆的module = function(){
var current = null;
var labels = {
'home':'home',
'articles':'articles',
'contact':'contact'
};
var init = function(){
};
var show = function(){
current = 1;
};
var hide = function(){
show();
}
return{init:init, show:show, current:current}
}();
module.init();