//利用ES6 的class构造函数
class bus{
constructor (){
this.item = {} //传入接受的
}
$on(name,fu){
// if(!this.item[name]){
// this.item[name] = []
// }
(this.item[name] ||= []).push(fu)
}
//
$emit(name,...a){
if(!this.item[name]) return;
this.item[name].forEach(cd =>cd(a));
console.log( this.item)
}
$off(name){
this.item[name] = []
}
}
网友评论