【发布时间】:2017-12-18 19:44:24
【问题描述】:
是否可以在静态方法中使用 ES6 创建 self/this 的新实例?例如;
class myClass {
static model() {
return new this;
}
}
这种场景有公认的模式吗?
非常感谢。
【问题讨论】:
是否可以在静态方法中使用 ES6 创建 self/this 的新实例?例如;
class myClass {
static model() {
return new this;
}
}
这种场景有公认的模式吗?
非常感谢。
【问题讨论】:
是的,这正是你要做的。
如果您不希望子类使用子类构造函数,请通过名称显式引用您的类,类似于 accessing other static methods。
【讨论】: