2011-07-14 4 views
0

コンテナ、ステージ、ビューの3つのクラスがあります。 Stageはコンテナから継承し、ビューはコンテナからも継承します。私はViewクラス(Viewオブジェクト)のインスタンスにinstanceofを呼び出すと、私は次のような結果が親クラスのtrueを返すDojo instanceof

dojo.declare("View", [Container] , { 
    constructor: function(){ 
     console.log(this.name + ' is a container-> ' + (this instanceof Container)); 
     console.log(this.name + ' is a View-> ' + (this instanceof View)); 
     console.log(this.name + ' is a Stage-> ' + (this instanceof Stage)); 
     this.preLoad(); 
    }, 
}); 

出力は私が子供のクラス名/タイプを見つけるにはどうすればよい

XYZ is a container -> true 
XYZ is a View -> true 
XYZ is a Stage -> false 

あり得ますか?

this多重継承のための回避策を提供していますが、それは私はあなたが提供されたリンクにビットさらに可能性のある解決策を見つけることができ

答えて

2

を探していたものではないのです。http://dojotoolkit.org/reference-guide/dojo/declare.html#meta-information

を基本的には、作成した任意のオブジェクトdeclareのクラスには、そのクラスに名前を付けた場合、declaredClassという属性があります。そうすることができます:

dojo.declare('ns.Foo', [], {}); 
dojo.declare('ns.Bar', [ns.Foo], {}); 

var x = new ns.Bar(); 
console.log(x.declaredClass == 'ns.Bar'); // true 
関連する問題