2016-08-03 20:02
浙江工业大学 前端工程师 五行缺心:涉及兼容性和参数问题
var Event = {
on : function(eventName, callback){
this[eventName] = this[eventName] || new Array();
this[eventName].push(callback);
},
emit : function(eventName){
if(this[eventName]){
var i, func;
for(i = 0; func = this[eventName][i]; i++){
if(func.length <= 0){
func.call(this);
}else{
var args = Array.prototype.slice.call(arguments, 1);
func.apply(this, args);
}
}
}else{
return console.log(undefined);
}
}
}

0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: