yan*_*rab 1 javascript typescript
是否可以从基构造函数中获取派生类名称?
class Entity {
constructor() {
// how to log here a class?
console.log('a')
}
}
class a extends Entity {}
new a()
Run Code Online (Sandbox Code Playgroud)
您可以使用 JavaScript/TypeScript 输出函数的名称Function.name,请参阅此答案:
class Entity {
constructor() {
console.log(this.constructor.name)
}
}
class A extends Entity {}
const a = new A();
console.log(a.constructor.name);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1442 次 |
| 最近记录: |