til

Javascript Event

NodeJs的events模块 onaddListener方法类似于jQuery中的on
字符串”hello”是一个触发事件, myEvent.emit("hello ")匹配触发事件, 执行后面的函数, 打印”world”

const event = require('events');
let myEvent = new event.EventEmitter();

myEvent.on("hello", function (msg) {
  console.log(msg)
});

myEvent.emit("hello", "world") //world