當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Node.js EventEmitter emitter.eventNames()用法及代碼示例

emitter.eventNames()

添加於:v6.0.0

返回一個數組,列出發射器已為其注冊偵聽器的事件。數組中的值是字符串或 Symbol s。

const EventEmitter = require('node:events');
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});

const sym = Symbol('symbol');
myEE.on(sym, () => {});

console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]

相關用法


注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 emitter.eventNames()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。