[英]ES6 classes: is it possible to access the constructor of a child class from the parent?
Using ES6 class syntax, is it possible to create a new instance of the current class from the parent?使用 ES6 类语法,是否可以从父类创建当前类的新实例? 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.我正在寻找类似于 PHP 的
new self()
语法的东西。
您可以通过this.constructor
访问当前实例的构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.