📅  最后修改于: 2022-03-11 15:02:32.260000             🧑  作者: Mango
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {
foo() {
this.emit('test');
}
}
const myEmitter = new MyEmitter();
myEmitter.on('test', () => console.log('Yay, it works!'));
myEmitter.foo(); // Yay it works!