var myModule = {
myProperty:"someValue",
myConfig:{
useCaching:true,
language:"en"
},
//基本方法
myMethod:function(){
//...
},
//根据当前配置输出信息
myMethod2:function(){
console.log("Caching is:"+(this.myConfing.useCaching) ? "enabled":"disabled");
},
//重写当前配置
myMethod3:function(newConfig) {
if(typeof newConfig ==="object"){
this.myConfig = newConfig;
console.log(this.myConfig.language);
}
},
};
myModule.myMethod3({
language:"fr",
usecaching:false
})
var testModule = (function(){
var counter = 0;
return {
incrementCounter:function(){
return ++counter;
},
resetCounter:function(){
console.log("counter value prior to reset" + counter);
counter = 0;
}
}
})();
//增加计数器
testModule.incrementCounter();
//检查计数器值并重置
testModule.resetCounter();
//包含命名空间、公有、和私有变量的Module模式
var myNamspace = (function(){
//私有计数器变量
var myPrivateVar = 0;
//记录素有参数的私有函数
var myPrivateMethod = function(foo){
console.log(foo);
};
return {
//公有变量
muPublicVar:"foo",
//调用私有变量和方法的公有函数
myPublicFunction:function(bar){
myPrivateVar++;
myPrivateMethod(bar);
}
}
})();
//全局模块
var myModule = (function(jQ,_){
function privateMethod1(){
jQ(".container").html(test);
}
return {
publicMethod:function(){
privateMethod1();
}
}
})(jQuery,_);
myModule.publicMethod();
//全局模块
var myModule = (function(){
//模块对象
var module = {};
privateVariale = "Hello";
function privateMethod(){
//...
}
module.publicproperty = "Foobar";
module.publiceMethod = function(){
}
return module;
})();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有