Using ES6 class syntax, is it possible to create a new instance of the current class from the parent? For example:
class Base {
withFoo() {
return new self({ foo: true });
}
}
class Child extends Base {}
(new Child()).withFoo();
I'm looking for something similar to PHP's new self() syntax.
You can access the current instance's constructor via this.constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With