Created
April 5, 2019 16:40
-
-
Save ositowang/a1eabc11f758a174f2d81397f37ea844 to your computer and use it in GitHub Desktop.
inheritance based on constructor stealing
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
/** | |
* Constructor stealing. As the name says, we steal the constructor from super | |
* class | |
* 1. We cant get values and methods from prototype | |
*/ | |
function daddy(name) { | |
this.name = name; | |
} | |
function son(name) { | |
// reset the superclass this binding to the subclass and passed in params | |
daddy.call(this, name); | |
} | |
let son1 = new son('jimmy'); | |
console.log(son1.name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment