有没有办法从 Javascript class 方法中引用 "the current class"

Is there a way to reference "the current class" from a Javascript class method

我想知道是否有一种方法可以从 Javascript class 中按名称引用“当前 class”而不是 class。

例如:

class MyBase{
    static makeNew(id){
        const newInstance = new --currentClass--;// magic happens here
        newInstance.id = id;
        return newInstance;
    }
}

class A extends MyBase{}
class B extends MyBase{}

const newA = A.makeNew(1);
const newB = B.makeNew(379);

有没有一种方法可以让我以这样的方式编写 MyBase::makeNew,当从 A class 调用它时,它 returns [的新实例=15=],但是当从 B class 调用时,它 returns B?

的新实例

因为调用签名如下:

A.makeNew(1);
B.makeNew(379);

这可能看起来很眼熟 - 您可以使用 this 来引用它所调用的对象。

class MyBase{
    static makeNew(id){
        const newInstance = new this();
        newInstance.id = id;
        return newInstance;
    }
}

class A extends MyBase{}
class B extends MyBase{}

const newA = A.makeNew(1);
const newB = B.makeNew(379);

console.log(newA instanceof A);
console.log(newB instanceof B);