1.概述
Events模块是对node“发布”/“订阅”的实现(虽然我具体不太懂…但是大致知道怎么用,日后再来分析这句话吧)
先来一段代码试试水:
var EventEmitter = require('events').EventEmitter;
var ee = new EventEmitter();
ee.on('someEvent', function () {
console.log('event has occured');
});
function f() {
console.log('start');
ee.emit('someEvent');
console.log('end');
}
f()
// start
// event has occured
// end
从输出的结果来看,很明显EventEmitter对象的事件触发和监听是同步的
Event对象
最新推荐文章于 2020-09-01 08:55:32 发布