Skip to content

Instantly share code, notes, and snippets.

@dyoder
Created September 20, 2012 21:25
Show Gist options
  • Save dyoder/3758442 to your computer and use it in GitHub Desktop.
Save dyoder/3758442 to your computer and use it in GitHub Desktop.
Event wrapper
_emit = EventEmitter.prototype.emit
EventEmitter.prototype.emit = ->
console.log arguments[0]
_emit(arguments)
_emit = myStream.emit
myStream.emit = ->
# ...
trace = (thing,label="Emit") ->
unless thing.emit?.apply?
throw "trace called on object with no 'emit' function: #{thing}"
emit = thing.emit
thing.emit = ->
console.log("#{label}: #{arguments[0]}")
emit(arguments)
thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment