使用ES6创建此实例

问题描述 投票:-1回答:1

是否可以在静态方法中使用ES6创建一个新的self / this实例?例如;

class myClass {

  static model() {

    return new this;
  }
}

这种情况是否有公认的模式?

非常感谢。

javascript ecmascript-6
1个回答
4
投票

是的,这正是你做的。

如果您不希望子类使用子类构造函数,请明确地按名称引用您的类,类似于accessing other static methods

© www.soinside.com 2019 - 2024. All rights reserved.