Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/ext/node/polyfills/events.ts>getEventListeners

A modern runtime for JavaScript and TypeScript.
Latest
function getEventListeners
import { getEventListeners } from "https://deno.land/x/deno@v2.0.4/ext/node/polyfills/events.ts";

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.

const { getEventListeners, EventEmitter } = require('events');

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

Parameters

name: string | symbol

Returns

Function[]