Created
August 9, 2012 16:23
-
-
Save juandopazo/3305606 to your computer and use it in GitHub Desktop.
Inheriting constructor properties with __proto__
This file contains 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
function Superclass() { | |
} | |
Superclass.prototype.someMethod = function () { | |
console.log('foo'); | |
}; | |
Superclass.staticMethod = function () { | |
console.log('I\'m "static"'); | |
}; | |
function Subclass() { | |
} | |
Subclass.__proto__ = Superclass; // this makes Subclass.staticMethod() work | |
Subclass.prototype = Object.create(Superclass.prototype); // this makes (new Subclass()).someMethod() work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But proto is a non-standard way of accessing the internal prototype...I feel confused because you prefer proto instead of classic prototype :-)