var eventCenter =
{
sub:function(mesName, mesCallback){
this.argus=this.argus||{};
this.argus[mesName]=this.argus[mesName]||[];
this.argus[mesName].push(mesCallback);
},
pub:function(){
var args=Array.prototype.slice.call(arguments,0);
var mesName=args.shift();
if(!this.argus || !this.argus[mesName]){
return this;
}
for(var i=0;i<this.argus[mesName].length;i++){
this.argus[mesName][i].apply(this,args)
}
}
}
//js事件订阅
eventCenter.sub('a',function(){
console.log(2);
});
eventCenter.sub('remote',function(){
console.log('remote call');
});
eventCenter.sub('timeout',function(){
setTimeout(function() {
eventCenter.pub('remote');
}, 5000);
})
//js事件发布
eventCenter.pub('a');
eventCenter.pub('timeout');