我怎么能在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");
}
});
Run Code Online (Sandbox Code Playgroud)
如何直接从child.m1调用parent.m2而不调用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");
}
});
Run Code Online (Sandbox Code Playgroud)
当使用dojo的声明时,您可以this.inherited(arguments)在子函数中使用它来调用父函数,请参阅:
http://dojotoolkit.org/reference-guide/1.8/dojo/_base/declare.html#dojo-base-declare-safemixin
m1: function (arg) {
console.log("child.m1");
this.inherited(arguments);
}
Run Code Online (Sandbox Code Playgroud)