Class 父类返回true的Dojo实例
我有三个类:容器、舞台和视图。阶段继承自容器,视图也继承自容器。当我对视图类(视图对象)的实例调用Class 父类返回true的Dojo实例,class,dojo,base,Class,Dojo,Base,我有三个类:容器、舞台和视图。阶段继承自容器,视图也继承自容器。当我对视图类(视图对象)的实例调用instanceof时,我得到以下结果 dojo.declare("View", [Container] , { constructor: function(){ console.log(this.name + ' is a container-> ' + (this instanceof Container)); console.log(this.na
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
如何查找子类名称/类型
提供了多重继承的解决方案,但这不是我要寻找的您可以在您提供的链接中进一步找到可能的解决方案: 基本上,从
declare
'd类创建的任何对象都具有declaredClass
属性(如果您命名该类)。因此,您可以:
dojo.declare('ns.Foo', [], {});
dojo.declare('ns.Bar', [ns.Foo], {});
var x = new ns.Bar();
console.log(x.declaredClass == 'ns.Bar'); // true