SOURCE

class Vue {
    constructor() {
        this.listeners = {}
    }

    // 订阅
    on(event, callback) {
        if (!this.listeners[event]) {
            this.listeners[event] = []
        }
        this.listeners[event].push(callback)
    }
    emit(event, args) {
        args = Array.prototype.slice.call(arguments, 1)
        let res 
        this.listeners[event].forEach(cb => {
            res = cb.call(this, ...args)
        })
        return res 
    }
}

const vue = new Vue()
// 相当于 @click = () => {}
vue.on('click', (value)=> {
    console.log(value)
})
vue.emit('click', 'asdf', 23)
console 命令行工具 X clear

                    
>
console