SOURCE

function Events(){
  this.on = function(eventName, callback){
    if(!this.handles){
      this.handles = {}
    }
    if(!this.handles[eventName]) {
      this.handles[eventName] = []
    }
    this.handles[eventName].push(callback)
  }
  this.emit = function(eventName, obj) {
    if(this.handles[eventName]){
      for(var i in this.handles[eventName]){
        this.handles[eventName][i](obj)
      }
    }
  }
  return this
}

 var events=new Events();
events.on('say', function(obj){
  console.log(obj)
})
events.on('say', function(obj){
  console.log(obj)
})


events.emit('say', 'hai')
console 命令行工具 X clear

                    
>
console