事件中心:eventhub
window.eventHub={
events:{},
emit(eventName,data){
for(let key in this.events){
if (key===eventName){
let fnList=this.events[key]
fnList.map((fn)=>{
fn.call(undefined,data)
})
}
}
},
on(eventName,fn){
if (this.events[eventName]===undefined){
this.events[eventName]=[]
}
this.events[eventName].push(fn)
}
}
网友评论