Skip to content

Instantly share code, notes, and snippets.

@extrabacon
Created March 25, 2014 16:45
Show Gist options
  • Save extrabacon/9766054 to your computer and use it in GitHub Desktop.
Save extrabacon/9766054 to your computer and use it in GitHub Desktop.
Proper inheritance with Javascript (sample with Node EventEmitter)
var EventEmitter = require('events').EventEmitter;
var MyClass = function () {
// invoke base constructor - optionally with parameters
EventEmitter.call(this);
// initialization goes here
// ...
};
// copy base prototype
MyClass.prototype = Object.create(EventEmitter.prototype);
// extend prototype here
MyClass.prototype.method = function () {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment