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.
您可以通过this.constructor
访问当前实例的构造函数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.