SOURCE

class EventEmitt {
    constructor () {
        this.handlers = {}
    }
    on (eventName, cb) {
      if (!this.handlers[eventName]) {
          this.handlers[eventName] = []
      }
      this.handlers[eventName].push(cb)
    }
    emit (eventName, ...args) {
      if (this.handlers[eventName]) {
        this.handlers[eventName].forEach(callback => {
            callback(...args)
        })
      }
    }
}
console 命令行工具 X clear

                    
>
console