Use EventEmitter in ES6 class

后端 未结 2 1453
栀梦
栀梦 2021-02-18 13:07

I am trying to get the EventEmitter in my own class running in ES6:

\"use strict\";
const EventEmitter = require(\'events\');

class Client extends EventEmitter{         


        
2条回答
  •  死守一世寂寞
    2021-02-18 14:07

    Events are synchronous - you're firing it before you are listening. Use

    const testClient = new Client(1,2,3,4,5);
    testClient.on('event', () => {console.log('triggered!')} );
    testClient.eventTest();
    

提交回复
热议问题