【发布时间】:2020-07-20 15:01:48
【问题描述】:
我正在尝试从静态和常规 getter 中创建父类的新实例。这适用于静态吸气剂,但不适用于常规吸气剂。
class Example {
static get clone() {
return new this();
}
get clone() {
return new this();
}
}
在this 上使用Example 有效但导致无法从此类扩展。
class Example {
static get clone() {
return new Example();
}
get clone() {
return new Example();
}
}
如何在非静态 getter 中使用 new this?
【问题讨论】:
标签: typescript class inheritance instance getter