SOURCE

function subscripe(){
    this.pood = [];
    function add(fn){
        console.log("add "+fn.name)
        this.pood.forEach(function(item){
            if(fn===item)return;
        }) 
        this.pood.push(fn);
    }

    function remove(fn){
         console.log("remove "+fn.name)
        this.pood.forEach(function(item,index){
            fn===item ?  this.pood.splice(index,1) : null
        }) 
    }

    function fire(...arg){
        this.pood.forEach((item,index)=>{
            item(...arg);
        })
    }
   
    return {
        pood:[],
        add,
        remove,
        fire
    }
}
var subscripe = new subscripe();
var fn1 = function(){
    
    console.log("1",arguments)
}
var fn2 = function(){
    console.log("2",arguments)
}
var fn3 = function(){
    console.log("3",arguments)
}
subscripe.add(fn1);
subscripe.add(fn2);
subscripe.add(fn3);
subscripe.fire(10,20);
console 命令行工具 X clear

                    
>
console