Skip to content

Latest commit

 

History

History
20 lines (13 loc) · 412 Bytes

event.md

File metadata and controls

20 lines (13 loc) · 412 Bytes

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