📜  节点js stackoverflow中的事件发射器 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:04:30.435000             🧑  作者: Mango

代码示例1
const events = require('events'); 

const eventEmitter = new events.EventEmitter();

eventEmitter.on('scream', function() {
    console.log("Screaming");
});

eventEmitter.on('scream', function(name) {
    console.log(name+" is screaming");
});

eventEmitter.emit('scream', 'Bob');