const EventEmitter = require(‘events‘); class MyEmitter extends EventEmitter {} const myev = new MyEmitter(); myev.on(‘event‘,function(a,b){ console.log(a,b,this); }) myev.emit(‘event‘,"hello","world"); const myEmitter = new MyEmitter(); myEmitter.on(‘event‘, (a, b) => { setImmediate(() => { console.log(a+b+‘这个是异步发生的‘); }); }); myEmitter.emit(‘event‘, ‘a‘, ‘b‘);
时间: 2025-01-12 21:30:30