SOURCE

class Func{
    constructor (){
        this.obj = {}
    }
    subscribe = (key,callbackk)=>{
        if(!this.obj[key]){
            this.obj[key] = []
        }
        this.obj[key].push(callbackk);
    }
    publish = (key,param)=>{
        console.log('pushlicjh',this.obj)
        this.obj[key].map((item)=>{
            item(param);
        })
    }

    off = (key,callback)=>{
        if(this.obj[key]){
            this.obj[key].splice(this.obj[key].findIndex(callback),1)
        }
        console.log(this.obj)
    }
}

const callbackk = (param)=>{
    console.log('wo ai ',param);
}

const fn = new Func()
fn.subscribe('param',callbackk)
fn.publish('param','nj')
fn.off('param',callbackk)
console 命令行工具 X clear

                    
>
console