Skip to content

Instantly share code, notes, and snippets.

@alxarch
Last active December 10, 2015 03:48
Show Gist options
  • Save alxarch/4376824 to your computer and use it in GitHub Desktop.
Save alxarch/4376824 to your computer and use it in GitHub Desktop.
var Events = function(){};
Events.prototype = {
events: {},
on: function(eventName, callback, context){
if(!this.events[eventName]){
this.events[eventName] = [];
}
this.events[eventName].push([callback, context || this]);
},
trigger: function(event){
var i, max,
actions = this.events[event],
args = Array.prototype.slice(arguments, 1);
if(actions){
for (i=0, max=actions.length; i < max; i++){
if(false === actions[i][0].call(actions[i][1], args)){
break;
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment