-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoiding super ambiguity #339
Comments
Returning an object from a constructor: class Foo extends Bar {
constructor() {
let o = new Bar();
o.somethingCustom = true;
return o;
}
} I don't know when you'd want to do such a thing, I only know that it's possible. When you return an object from the constructor, it's the same as returning an object from a function. There is no relationship to |
@nzakas coming back to this half a year later, the object returned from the constructor is the one assigned to the constructed class's own properties. example:lets create a base class class BaseClass {
constructor() {
this.state = "I am base.";
}
} normal case (calling super method):class NormalCase extends BaseClass {
constructor() {
super();
}
}
new NormalCase().state // "I am base." Returning an object from constructor
finally, it has nothing to do with super or inheritance at all.
So in conclusion:
possible use case: |
I'm reading your book and its a great read so far! thanks.
In the classes section, talking about super you mentioned the following:
Can you please further elaborate why would you need to avoid using super? and what do you mean by "return an object from the class constructor."? does this object becomes the new "this"?
The text was updated successfully, but these errors were encountered: