Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var EventEmitter = require("events").EventEmitter;
var emitter = new EventEmitter();
emitter.once("foo", function() {
console.log("foo");
});
emitter.on("foo", function() {
console.log("bar");
});
var listeners = emitter.listeners("foo"); // => [function(){} bound with "once", function(){} bound with "on"]
listeners.length; // => 2
listeners[0](); // Manually calling the listener that was bound with "once" removes it from the array
listeners.length; // => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment