我正在尝试在节点 REPl 中运行此代码
var E = require('events').EventEmitter;
var e = new E(); //controller
e.on('msg', function(){ console.log(1) }); //handling
(function(){
console.log(0);
e.emit('msg');
console.log(2);
}()); //self-execution
所以它在控制台中给出
0
1
2
这是否意味着事件发射是同步的,并且代码在某种程度上等于:
(function(){
console.log(0);
console.log(1);
console.log(2);
}()); //self-execution