我怎样才能在dojo中调用另一种方法的父方法。 考虑下面的例子:如何在dojo中调用另一种方法的父方法
var parent = declare(null,{
m1: function(arg){
console.log("parent.m1");
},
m2: function(arg){
console.log("parent.m2");
}
});`enter code here`
var child = declare(parent,{
m1: function(arg){
console.log("child.m1");
// how can i call parent.**m2** here directly without calling child.m2
},
m2: function(arg){
console.log("child.m2");
}
});
我怎样才能直接调用parent.m2从child.m1没有在所有
调用child.m2现在假设我定义了两个模块,如下所示:
parentModule.js
var parent = declare(null,{
m1: function(arg){
console.log("parent.m1");
},
m2: function(arg){
console.log("parent.m2");
}
});
return declare("ParentModule",[parent,child]);
//******************************************//
childModule.js
return declare("child",null,{
m1: function(arg){
console.log("child.m1");
// how can i call parent.**m2** here directly without calling child.m2
//if we call ParentModule.prototype.m2.call(this,arguments); this will call child.m2
//as child module override the parent now
//also calling this.getInherited("m2",arguments); will call child.m2 !!!
//how to fix that?
},
m2: function(arg){
console.log("child.m2");
}
});
我很困惑你的层次结构。为什么父母延长孩子?难道不是相反吗?我发布了一个jsfiddle,展示了我认为你应该如何定义你的模块。 – 2013-03-06 21:23:37