emitter.rawListeners(eventName)


返回名为 eventName 的事件的监听器数组的副本,包括任何封装器(例如由 .once() 创建的封装器)。

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

// 返回具有函数 `onceWrapper` 的新数组,
// 该函数具有属性 `listener`,其中包含上面绑定的原始监听器
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];

// 将"log once"记录到控制台并且不会解除 `once` 事件的绑定
logFnWrapper.listener();

// 将"log once"记录到控制台并删除监听器
logFnWrapper();

emitter.on('log', () => console.log('log persistently'));
// 将返回新数组,其中包含由上面的 `.on()` 绑定的函数
const newListeners = emitter.rawListeners('log');

// 记录"log persistently"两次
newListeners[0]();
emitter.emit('log');

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');