(function (global) {
* 封装事件处理
* @param {[type]} el [description]
* @param {[type]} type [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
var $emit = function (el,type,callback) {
if (el.addEventListener) {
el.addEventListener(type,callback);
} else if(el.attachEvent){
el.attachEvent("on"+type,callback);
}else {
el[type] = callback;
}
};
global.$emit = $emit;
* 这是定义模块add
*/
var addModule = (function () {
return function () {
console.log("i'm add module ....");
}
})();
* 这是定义模块minus
*/
var minusModule = (function () {
return function () {
console.log("I'm minu module....");
}
})();
* 这是计算模块,依赖模块add 和模块minus
* @type {[type]}
*/
var calcModule = (function (add,minus) {
return {
add: add,
minus: minus
}
})(addModule,minusModule);
*这里是主模块
*/
$emit(document.getElementById('btnAdd'),"click",function () {
calcModule.add();
});
$emit(document.getElementById('btnMinus'),"click",function () {
calcModule.minus();
});
})(this);