涉及兼容性和参数问题 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);      }    } }
点赞 4

相关推荐

牛客网
牛客企业服务