我一直在抨擊我的頭,因爲我無法捕獲在Node.js中從此代碼發出的事件。我的直覺感覺是有一些超出範圍的,但我無法弄清楚它是什麼。 index.js
中的console.log
行代碼永遠不會被執行。我的活動沒有被排出?爲什麼我無法從Node.js中的擴展EventEmitter類捕獲事件?
player.js
index.js
const rocketPlayer = require('./player.js');
const player = new rocketPlayer();
player.on('nowPlaying', title => {
console.log('caught nowPlaying event');
});
//define a connection
player.update(connection)
堅持你的'update'和'play'方法裏面的一些日誌。從EventEmitter繼承是按原樣完成的。 – Adam
你在哪裏調用'.emit('nowPlaying',{})' – magreenberg
我在播放函數中有一些日誌記錄,它在發出呼叫之後出現,沒有錯誤。這讓我非常震驚,但事件並未被捕獲。 –