Otaqui.com Blog

Javascript EventEmitter Redux, now on github

I’ve added some more features to the EventEmitter mixin (like actually working listener removal) and posted it to github:

EventEmitter on github

It’s fairly simple to use … something like this:

var MyKlass = function() {};
EventEmitter.augment(MyKlass.prototype);
/**
 * Show me
 *
 * @fires shown
 */
MyKlass.prototype.showMe = function() {
  this.trigger('shown', {'visible':true});
}
var myInstance = new MyKlass();
myInstance.on('shown', function(e) {
  console.log(e.visible);
}
myInstance.showMe();