function Event(){ this.demo = [] this.results = [] } //订阅 Event.prototype.on = function(callback){ this.demo.push(callback) } //发布 Event.prototype.emit = function(data){ this.results.push(data) this.demo.forEach(fn => { console.log(data,this.results,8888) fn(this.results) }) } var e = new Event() e.on(function(data){ console.log(data,111) }) e.on(function(data){ console.log(data,22) }) e.emit(22) e.emit(333)