Skip to content

Instantly share code, notes, and snippets.

@asiletto
Created January 24, 2014 15:28
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 asiletto/8599473 to your computer and use it in GitHub Desktop.
Save asiletto/8599473 to your computer and use it in GitHub Desktop.
function EventEmitter(){}
EventEmitter.prototype.on = function(event, fct){
this._events = this._events || {};
this._events[event] = this._events[event] || [];
this._events[event].push(fct);
};
EventEmitter.prototype.emit = function(event /* , args... */){
this._events = this._events || {};
if( event in this._events === false ) return;
for(var i = 0; i < this._events[event].length; i++){
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment