class subscripe {
constructor (){
this.pood = []
}
add(fn){
let index = this.pood.indexOf(fn);
index>0 ?null : this.pood.push(fn);
}
remove(fn){
let index = this.pood.indexOf(fn);
index>0 ? this.pood.splice(index,1) : null;
}
fire(...arg){
this.pood.forEach(item=>{
item(...arg);
}
)
}
}
let sub = new subscripe();
let fn1 =(...arg)=>{
console.log(1,arg)
}
let fn2 =(...arg)=>{
console.log(2,arg)
}
let fn3 =(...arg)=>{
console.log(3,arg)
}
sub.add(fn1)
sub.add(fn2)
sub.add(fn3)
sub.fire(10,20)
sub.remove(fn2)
sub.fire(10,20)
console