私はクラスとそのクラスを拡張する別のクラスを持っています。ES6でスーパークラス名を取得
class Shape {
constructor() {
return this;
}
}
class Circle extends Shape {
constructor() {
super();
return this;
}
}
let foo = new Circle();
私は
let className = foo.constructor.name
// returns string 'Circle'
と、fooのクラスを取得することができ、同様の方法で、fooのスーパークラス(「形」)の名前を取得することが可能ですか?
'foo .__ proto __。constructor.name'?私は '__proto__'も標準化されていると思います。 –
それはあなたに親クラスを与えますが、必ずしもオブジェクトが直接拡張していたクラスである必要はなく、元々拡張したクラスである必要はありません。 – joshstrike
ありがとうJan - 元のクラスをもう一度返しますが、foo.__proto__.__proto__.constructor.nameはそれを取得します。 – joelg