这个问题的流行语是this.inherited(arguments);
你的问题是调用一个不在当前继承范围内的方法 - 并且一个真正的面向对象的程序员会被称为无效..但是它是可能的(仍然)因为加载器声明了全局范围内的所有内容,例如你可以访问任何模块通过mynamespace.X 然后添加原型.theMethod。
一旦你像在 mynamespace.B 中一样拥有继承,A 和 B 的所有功能都是“this”范围的。它就像是东西的合并散列,比如说for all methods and variables in A do set instance B[key] = property A[key]
。
但是,如果您遇到覆盖,其中属性为“类”A 和 B 的原型 - 声明/构造链中有一种机制允许调用“超级”(或父类,遵循您的符号)。
对于特殊属性构造函数来说,继承冒泡[期间]总是如此。
对于仅声明一次的任何方法,如果它不是继承的方法,您就不能自己调用它 - 然后可以通过“this”访问它
对于任何具有覆盖的方法,函数 'this.inherited(arguments);' 将向您向上发送一个刻度线到当前的被调用者父类。看看这里的扩展小提琴
var AClass = dojo.declare("mynamespace.A", null, {
constructor: function(args) {
this.overriddenMethod();
},
overriddenMethod: function() {
}
});
var BClass = dojo.declare("mynamespace.B", [AClass], {
constructor: function() { },
overriddenMethod: function() {
// call super before anything else is processed in this method
// by placing following call you can control function callflow
this.inherited(arguments);
}
});
// will call A.constructor, then A.overriddenMethod
new AClass();
// will call B.constructor, A.constructor, B.overriddenMethod and then
// A.overriddenMethod via the call to super
// in B.overriddenMethod which A.constructor
// calls (note that A.constructor callflow 'aims' B.override not A.override)
new BClass();