node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org ยป



A portable event emitter class


var EventEmitter = require('ee-event-emitter');
var eventEmitter = new EventEmitter();

// attach listener
eventEmitter.on('eventName', cb);

// attach listsner which is called once
eventEmitter.once('eventName', cb);

// remove all listeners for all events;

// remove listeners for specific event'eventName');

// remove a single listener'eventName', listener);

// emit an event
eventEmitter.emit('eventName', arg, arg, ....);

// get all listeners

// get lsisteners for a specific event

// event which is emitted when an event listener is added
eventEmitter.on('listener', function(eventName, listener){});

// event which is emitted when an event listener is removed
eventEmitter.on('removeListener', function(eventName, listener ){});


var   Class     		= require('ee-class')
	, EventEmitter    	= require('ee-event-emitter');

var Human = new Class({
      ssinherits: EventEmitter
    , name: ''
    , age: 29

    , init: function(options) { =;

    , sayHello: function(to) {
        console.log('Hi %s, my name is %s, i'm %s years old.', to,, this.age);

var Boy = new Class({
      inherits: Human
    , age: 12

var dylan = new Boy({
    name: 'Dylan'

dylan.on('startHello', function() {
	console.log('starting console output:');

dylan.on('endHello', function() {
	console.log('finished console output:');

dylan.sayHello('michael');  // starting console output:
                            // Hi my name is Dylan and i'm 12 years old.
                      		// finished console output!