events.listenerCount(emitter, eventName)


    返回在给定 emitter 上注册的给定 eventName 的监听器数量的类方法。

    Stability: 0 - Deprecated: Use emitter.listenerCount() instead.

    A class method that returns the number of listeners for the given eventName registered on the given emitter.

    import { EventEmitter, listenerCount } from 'node:events';
    
    const myEmitter = new EventEmitter();
    myEmitter.on('event', () => {});
    myEmitter.on('event', () => {});
    console.log(listenerCount(myEmitter, 'event'));
    // Prints: 2const { EventEmitter, listenerCount } = require('node:events');
    
    const myEmitter = new EventEmitter();
    myEmitter.on('event', () => {});
    myEmitter.on('event', () => {});
    console.log(listenerCount(myEmitter, 'event'));
    // Prints: 2