Last active
December 10, 2015 03:48
-
-
Save alxarch/4376824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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