node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


prototype-emitter Flattr this!experimental

Define EventEmitter listeners on a class to save on memory consumption in exchange for a little bit of extra work emitting the events themselves.

Suitable when you've got a lot of mostly similar EventEmitters, and you're not emitting enough events for it to be a performance bottleneck.

See also: bindle




Returns a new prototype-emitter class. Optionally you can pass a BaseClass in as the first argument to mixin prototype-emitter functionality.

Once created or mixed in, you can add event listeners directly on the class before (or after) creating instances of it. These listeners will be available on each instance, so calling ee.emit will trigger these listeners too.

var PrototypeEmitter = require('prototype-emitter')
var CustomEmitter = PrototypeEmitter()
CustomEmitter.once('data', function() {
  console.log('data recieved: ')
CustomEmitter.on('data', function(data) {
  console.log('>>', data)
var emitter = new CustomEmitter
emitter.on('data', function(data) {
  console.log(' >', data)
emitter.emit('data', 1)
emitter.emit('data', 2)
emitter.emit('data', 3)
// data recieved: 
// >> 1 
//  > 1 
// >> 2 
//  > 2 
// >> 3 
//  > 3 


MIT. See for details.