![](/img/trans.png)
[英]ES6 using static method to create new instance gives undefined for child class attributes
[英]Create new instance of this using ES6
是否可以在静态方法中使用ES6创建self / this的新实例? 例如;
class myClass {
static model() {
return new this;
}
}
这种情况是否存在公认的模式?
非常感谢。
是的,这就是您的做法。
如果您不希望子类使用子类构造函数,则可以通过名称显式地引用您的类,类似于访问其他静态方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.