模块化的放大模式 augmentation
一个模式调用另一个模块
var mod1 = (function() {
var test1 = function() {
console.log(1);
},
test2 = function() {
console.log(2);
},
test3 = function() {
console.log(3);
}
return {
test1: test1,
test2: test2,
test3: test3
}
})();
var mod2 = (function(mod) {
var test4 = function() {
console.log(4);
mod.test1();
},
test5 = function() {
console.log(5);
mod.test2();
},
test6 = function() {
console.log(6);
mod.test3();
}
return {
test4: test4,
test5: test5,
test6: test6
}
})(mod1);//模块化的放大模式 augmentation
宽放大模式 Loose augmentation
//多个人开发同一个模块的时候,可以使用以下模式
//宽放大模式 Loose augmentation
//module1.js
var mod = (function(module) {
module.b = 3;
module.test2 = function() {
console.log('test1')
}
return module;
})(mod||{});
//module2.js
var mod = (function(module) {
module.a = 1;
module.test1 = function() {
console.log('test1')
}
return module;
})(mod||{});
//直接引用使用