Skip to content

Instantly share code, notes, and snippets.

@arlando
Created December 5, 2014 19:13
Show Gist options
  • Save arlando/c627220b23fddede9f99 to your computer and use it in GitHub Desktop.
Save arlando/c627220b23fddede9f99 to your computer and use it in GitHub Desktop.
How to extend Node's EventEmitter
'use strict';
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var Bus;
var bus;
Bus = function () {
EventEmitter.call(this);
var self = this;
this.on('foo', function (data) {
console.log('bar', data);
});
}
util.inherits(Bus, EventEmitter);
//Bus.prototype = {} would clobber inherited properties from EventEmitter.
Bus.prototype.foo = function () {}
bus = new Bus();
bus.on('bar', function (data) {
console.log('buzz', data);
})
module.exports = bus;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment