对象中封装事件对应的各个函数,调用时遍历对象中的函数
let fs =require('fs');
fs.readFile("C:/Users/10853/Desktop/tt.txt",{flag:'r',encoding:"utf-8"},function(err,data){
console.log(data);
jeEvent.emit('ok',data);
})
var jeEvent={
event:{
},
on:function(name,fun){
if(this.event[name])
{
this.event[name].push(fun);
}else{
this.event[name]=[];
this.event[name].push(fun);
}
},
emit:function(name,data)
{
if(this.event[name]){
this.event[name].forEach(function(item,index){
item(data);
})
}
}
}
jeEvent.on('ok',function(eventMsg){
console.log('1');
})
jeEvent.on('ok',function(eventMsg){
console.log('2');
})
jeEvent.on('ok',function(eventMsg){
console.log('3');
})