Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created January 19, 2011 18:23
Show Gist options
  • Save isaacs/786587 to your computer and use it in GitHub Desktop.
Save isaacs/786587 to your computer and use it in GitHub Desktop.
var e = new (require("events").EventEmitter)
e.on("newListener", function (ev, fn) {
console.error(e.listeners(ev))
console.error("During: listeners.length = %d", e.listeners(ev).length)
})
console.error("Before: listeners.length = %d", e.listeners("foo").length)
e.on("foo", function () {})
console.error(e.listeners("foo"))
console.error("After: listeners.length = %d", e.listeners("foo").length)
/*
Before: listeners.length = 0
[]
During: listeners.length = 0
[ [Function] ]
After: listeners.length = 1
*/
@kilianc
Copy link

kilianc commented Jan 19, 2011

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment