gpt4 book ai didi

javascript - dojo中如何调用另一个方法的父方法

转载 作者:行者123 更新时间:2023-12-02 17:27:29 25 4
gpt4 key购买 nike

我如何调用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");
}

});

我怎样才能直接从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");
}

});

最佳答案

当使用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);
}

关于javascript - dojo中如何调用另一个方法的父方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15249717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com