Skip to content

Instantly share code, notes, and snippets.

@corpix
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpix/f720704802e504607a8d to your computer and use it in GitHub Desktop.
Save corpix/f720704802e504607a8d to your computer and use it in GitHub Desktop.
Delegate as monkey!
{EventEmitter} = require('events')
_emit = EventEmitter::emit
EventEmitter::emit = (type) ->
args = Array::slice.call(arguments)
res = _emit.apply(@, args)
if @_delegates and @_delegates[type]
for delegate in @_delegates[type]
if delegate.emit.apply(delegate, args)
res = true
res
EventEmitter::delegate = (type, eventemitter) ->
if not @_delegates
@_delegates = {}
if not @_delegates[type]
@_delegates[type] = []
@_delegates[type].push(eventemitter)
module.exports = {EventEmitter}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment