[英]Create new instance of this using ES6
Is it possible to create a new instance of self/this using ES6 inside a static method? 是否可以在静态方法中使用ES6创建self / this的新实例? For example;
例如;
class myClass {
static model() {
return new this;
}
}
Is there a recognised pattern for this type of scenario? 这种情况是否存在公认的模式?
Many thanks. 非常感谢。
Yes, this is exactly how you'd do it. 是的,这就是您的做法。
If you don't want subclasses to use the subclass constructors, refer to your class by name explicitly, similar to accessing other static methods . 如果您不希望子类使用子类构造函数,则可以通过名称显式地引用您的类,类似于访问其他静态方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.