从静态方法中创建实例

时间:2018-10-01 16:14:49

标签: javascript node.js class static

在PHP中,它是$instance = new static();

您如何在nodejs中做到这一点?

通过静态方法

1 个答案:

答案 0 :(得分:1)

this是指静态方法中的类构造函数。

是:

class Foo {
  static factory() {
    return new this();
  }
}

Foo.factory();