Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created January 17, 2013 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ralphholzmann/4559116 to your computer and use it in GitHub Desktop.
Save ralphholzmann/4559116 to your computer and use it in GitHub Desktop.
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