getEventListeners

fun getEventListeners(emitter: ERROR CLASS: Symbol not found for EventTarget, type: ERROR CLASS: Symbol not found for web.events.EventType<*>): ERROR CLASS: Symbol not found for js.array.ReadonlyArray<kotlin/Function<*>>(source)
fun getEventListeners(emitter: EventEmitter, type: EventType): ERROR CLASS: Symbol not found for js.array.ReadonlyArray<kotlin/Function<*>>(source)

Returns a copy of the array of listeners for the event named eventName.

For EventEmitters this behaves exactly the same as calling .listeners on the emitter.

For EventTargets this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes.

import { getEventListeners, EventEmitter } from 'node:events';

{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}

Since

v15.2.0, v14.17.0