Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Emitter(){
this.events = {};
}
Emitter.prototype.emit = function(eventType,data){
this.events[eventType].map(function(callback){
callback.call(null,data);
});
}
Emitter.prototype.on = function(eventType,callback){
(this.events[eventType] = this.events[eventType] || []).push(callback);
}
/*
example
a = new Emitter();
a.on('event1',function(){
console.log('event1 executed');
});
a.emit('event1');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment