Created
December 5, 2014 19:13
-
-
Save arlando/c627220b23fddede9f99 to your computer and use it in GitHub Desktop.
How to extend Node's EventEmitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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