class EventEmit{
constructor(){
this.events = []
}
on(type,listener){
this.events[type]||(this.events[type]=[]).push(listener)
console.log(this.events)
}
emit(type,...args){
if(this.events[type]){
this.events[type].forEach(fn=>{fn.call(type,...args)})
}
}
off(type,listener){
let index = this.events[type].indexOf(listener)
this.events[type].splice(index,1)
}
}
let event= new EventEmit()
event.on('say',function(str) {
console.log(str);
});
event.emit('say','visa');