SOURCE

class PubSub {
    constructor () {
        this.list = new Map
    }

    on (event, cb) {
        if (!this.list.has(event)) {
            this.list.set(event, [cb])
        } else {
            this.list.get(event).push(cb)
        }
    }

    emit (event, ...args) {
        this.list.get(event).forEach(cb => cb(...args))
    }


}

const pub1 = new PubSub
pub1.on('get', (a, b) => {console.log(a, b)})
pub1.on('get', () => {console.log(3)})  
pub1.emit('get', 1, 2)
console 命令行工具 X clear

                    
>
console