Created
September 16, 2015 04:16
-
-
Save chrisabrams/13d47d9b03d7cf0e8166 to your computer and use it in GitHub Desktop.
How do I get `this.foo` to be assigned to class B's prototype instead of class A's prototype?
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
/* | |
How do I get `this.foo` to be assigned to class B's prototype instead of class A's prototype? | |
*/ | |
class A { | |
constructor(options = {}) { | |
this.foo = options.foo | |
} | |
} | |
class B extends A { | |
constructor(options = {}) { | |
super(options) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not on any prototypes.
this.foo
is thefoo
property of an A or B object, whichever you constructed. Obvious for thenew A()
that it grows a new property, but also when younew B()
, theB
's ctor super calls intoA
's ctor - with the B object asthis
- and so sets thefoo
property on the B object.You're generally not going to be futzing with the prototypes once you have live objects, eg "assigning to prototypes".
What's the problem you're seeing?