make-emitter

event emitter constructor factory

npm install make-emitter
3 downloads in the last week
12 downloads in the last month

make-emitter

Build Status

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

api

function makeEmitter([object methods])

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.

example - old and busted:

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');
};

example - with make-emitter;

var emitter = require('make-emitter');
var CustomEmitter = emitter({
  explode: function() {
    this.emit('boom');
  }
});

incredible.

install

npm install make-emitter

test

npm test

license

MIT

npm loves you