Skip to content

Instantly share code, notes, and snippets.

@arian
Created March 3, 2012 09:51
Show Gist options
  • Save arian/1965264 to your computer and use it in GitHub Desktop.
Save arian/1965264 to your computer and use it in GitHub Desktop.
def(emi.prototype, "emit", function(event){
var listeners = this._listeners, events, off = []
this.off = function(_event, fn){
if (_event == event) off.push(fn)
else emi.prototype.off.call(this, _event, fn)
return this
};
if (listeners && (events = listeners[event])){
var args = Array.prototype.slice.call(arguments, 1)
for (var i = 0, l = events.length; i < l; i++) events[i].apply(null, args)
}
delete this.off
for (var ii = 0, ll = off.length; ii < ll; ii++) this.off(event, off[ii])
return this
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment