クラスからイベントを放出できますか?その後クラスからのイベントの送信
class MyEvent extends EventEmitter {
constructor(options) {
super();
this.options = options;
this.execute();
}
execute() {
// do something;
this.emit("close"); // Pass here to the instance.
}
}
:
const myEvent = MyEvent({});
myEvent.on("close", (data) => {
// do something here.
});
は現在、近いイベントは、クラスから呼び出されていません。しかし、ここでは=>https://coligo.io/nodejs-event-emitter/が働いています。
コンストラクタは決して何も実行してはいけません。その唯一の目的はインスタンスを初期化することです。 – Bergi