Created
March 25, 2014 16:45
-
-
Save extrabacon/9766054 to your computer and use it in GitHub Desktop.
Proper inheritance with Javascript (sample with Node 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
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