make-emitter

event emitter constructor factory

make-emitter

An event emitter constructor factory. Save ~3 lines of code with each use!

require('make-emitter') returns the function makeEmitter

The function make-emitter returns a constructor function for a new object which inherits from EventEmitter. Optionall you can supply a hash of methods which will be added to the prototype of the new Constructor.

var EventEmitter = require('events').EventEmitter;
var util = require('util');
 
var CustomEmitter = function() {
  EventEmitter.call(this);
};
 
util.inherits(CustomEmitter, EventEmitter);
 
CustomEmitter.prototype.explode = function() {
  this.emit('boom');
};
var emitter = require('make-emitter');
var CustomEmitter = emitter({
  explodefunction() {
    this.emit('boom');
  }
});

incredible.

npm install make-emitter
npm test

MIT