Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Last active August 29, 2015 14:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sTiLL-iLL/159bb55d8ac3cf4356fc to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/159bb55d8ac3cf4356fc to your computer and use it in GitHub Desktop.
An example of inheriting from event emitter
// Require our emitter
var Emitter = require('events').EventEmitter;
// Our main constructor
var myEmitter = function (config) {
// extend with emitter
Emitter.call(this);
};
// Inherit from emitter, but keep my constructor
myEmitter.prototype = Object.create(Emitter.prototype, {
constructor: {
value: myEmitter
}
});
// methods
myEmitter.prototype.setName = function (nam) {
this.name = nam;
this.emit('nameChanged', name);
};
module.exports = myEmitter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment