EventEmitter.listenerCount(emitter, eventName)
稳定性: 0 - 弃用: 改为使用
emitter.listenerCount()
。emitter
<EventEmitter> 要查询的触发器eventName
<string> | <symbol> 事件名称
返回在给定 emitter
上注册的给定 eventName
的监听器数量的类方法。
const myEmitter = new MyEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(EventEmitter.listenerCount(myEmitter, 'event'));
// 打印: 2
Stability: 0 - Deprecated: Use
emitter.listenerCount()
instead.emitter
<EventEmitter> The emitter to queryeventName
<string> | <symbol> The event name
A class method that returns the number of listeners for the given eventName
registered on the given emitter
.
const myEmitter = new MyEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(EventEmitter.listenerCount(myEmitter, 'event'));
// Prints: 2