SOURCE

class Evente{
    constructor(){
        this.map={}
    }

    add(name,fn){
        if(this.map[name]){
            this.map[name].push(fn)
            return
        }
        this.map[name]=[fn];
        return;
    }

    emit(name,...args){
        this.map[name].forEach(fn=>{
            fn(...args)
        })
    }
}

let e = new Evente()
e.add('hello',(err,name)=>{
    if(err){
        console.error(err);
        return;
    }
    console.log(name)
})
console 命令行工具 X clear

                    
>
console