Skip to content

Instantly share code, notes, and snippets.

Created Sep 14, 2021
What would you like to do?
Class: EventEmitter
// Synchronously calls each of the listeners registered for the event named eventName,
// in the order they were registered, passing the supplied arguments to each.
emit(eventName[, ...args])
// Removes the specified listener from the listener array for the event named eventName.
off(eventName, listener)
// Adds the listener function to the end of the listeners array for the event named eventName.
// No checks are made to see if the listener has already been added.
// Multiple calls passing the same combination of eventName and listener will result in the listener being added,
// and called, multiple times.
on(eventName, listener)
// Adds a one-time listener function for the event named eventName.
// The next time eventName is triggered, this listener is removed and then invoked.
once(eventName, listener)
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment