Skip to content

Instantly share code, notes, and snippets.

@ismnoiet
Last active August 1, 2016 11:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ismnoiet/89591c470421e2a1f7de96ea4584fe35 to your computer and use it in GitHub Desktop.
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