Given class A and class B, where class B inherits from class A …
// Define class A
dojo.declare("mynamespace.A",null,{
myMethodA: function() { this.myMethodB() }
});
// Define class B
dojo.declare("mynamespace.B",mynamespace.A,{
myMethodB: function() {}
});
Is it legal to call this.myMethodB() in the scope of class A (parent class)?
I have seen this in a piece of software and I do not understand it. I know that in Java, this is not possible unless you typecast A to B. But is dojo any different?
Your buzzword of this question would be this.inherited(arguments);
Your question goes for calling a method which is not in the current inheritance scope – and would by a true object oriented programmer be called invalid.. However it is possible (still) since the loader declared everything in global scope, e.g. you can access any module via mynamespace.X and then add prototype.theMethod.
Once you have inheritance as in mynamespace.B all of the functionalities of both A and B are ‘this’ scoped. It is simply like a merged hash of stuff, say
for all methods and variables in A do set instance B[key] = property A[key].However if you would encounter an override where the property is prototyped for both ‘class’ A and B – there is a mechanism in the declare / construct chain which allows for calling ‘super’ (or parent class, following your notation).
For the special property constructor it is allways so, that the inheritance bubbles[period].
For any methods that are declared only once, you cannot with respect of yourself call it if it is not an inherited method – and it will then be accessible via ‘this’
For any methods which have overrides, the function ‘this.inherited(arguments);’ will send you upwards, one tick to the current parent class of callee. Look at the extended fiddle here