JavaScript 放大模式,宽放大模式 多人开发同一个模块

模块化的放大模式 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||{});

//直接引用使用
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值