8
私にはStarship -> Capital -> Omega
のような継承チェーンがあり、Omegaクラスのオブジェクトから "Omega"を取得できるようにしたいと考えています。Javascriptクラスの継承とすべての継承の名前?
function Starship(){
}
function Capital(){
Starship.call(this);
}
Capital.prototype = Object.create(Starship.prototype);
function Omega(){
Capital.call(this);
}
Omega.prototype = Object.create(Capital.prototype);
var omega = new Omega();
omega instanceof Omega // true
omega instanceof Capital// true
omega instanceof Starship // true
omega.constructor.name // Starship
オメガは、すなわち「オメガ」の一部であるか、または私はちょうどオメガ機能にthis.type = "Omega"
のようなものを追加する必要があることを最年少クラスを取得する方法はありますか?
すべての継承ライブラリはコンストラクタプロパティを「修正」する必要があります –