Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var EventEmitter = require("events").EventEmitter;
var emitter = new EventEmitter();
emitter.once("foo", function() {
emitter.on("foo", function() {
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