-
-
Save Integralist/6046756 to your computer and use it in GitHub Desktop.
JavaScript: inheritance by proxy
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
function inherit (child, parent) { | |
function proxy () {}; | |
proxy.prototype = parent.prototype; | |
child.prototype = new proxy(); | |
}; | |
function Parent () {} | |
function Child () {} | |
inherit(Child, Parent); | |
var child = new Child(); | |
console.log(child instanceof Child); // true | |
console.log(child instanceof Parent); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment