Skip to main content
Go to Latest
method EventEmitter.prototype.rawListeners
import { EventEmitter } from "https://deno.land/std@0.166.0/node/events.ts";

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));

// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];

// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();

// Logs "log once" to the console and removes the listener
logFnWrapper();

emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');

// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');

Parameters

eventName: string | symbol

Returns

Function[]