Skip to content

Instantly share code, notes, and snippets.

@esamattis
Created June 17, 2011 21:03
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 esamattis/1032342 to your computer and use it in GitHub Desktop.
Save esamattis/1032342 to your computer and use it in GitHub Desktop.
Node.js EventEmitter implemented with CoffeeScript and jQuery
# Target: http://nodejs.org/docs/v0.4.8/api/events.html
class JQEvenEmitter
constructor: -> @_jq = jQuery {}
on: -> @_jq.bind.apply @_jq, arguments
addListener: JQEvenEmitter::on
once: -> @_jq.one.apply @_jq, arguments
removeListener: -> @_jq.unbind.apply @_jq, arguments
removeAllListeners: JQEvenEmitter::removeListener
emit: -> @_jq.trigger.apply @_jq, arguments
# Missing only setMaxListeners and listeners array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment