PDA

View Full Version : Ext.extend and calling overridden methods



estesbubba
29 Nov 2011, 2:16 PM
Say I have the following classes





ControllerA = Ext.extend(Ext.Controller, {


id: 'BaseWorkflow',


init: function() {
},


index: function(options) {
...
},

handlerA: function() {
this.functionXYZ();
},

functionXYZ: function() {
}


});




ControllerB = Ext.extend(ControllerA, {


id: 'CurrentServices',


index: function(options) {
...
},




someHandler: function() {
ControllerB.superclass.index.call(this, {
initParams: 'abc'
});
},

functionXYZ: function() {
}


});




I'm in ControllerB and someHandler() gets called which calls ControllerB.superclass.index.call(). Now within ControllerA an event calls handlerA() which calls this.functionXYZ(). What happens is functionXYZ in ControllerA is called and not ControllerB. Inspecting this shows it's actually an instance of ControllerB.

So how do I get it to call ControllerB's function instead of ControllerA's?

mitchellsimoens
29 Nov 2011, 2:29 PM
So in someHandler in ControllerB you want to call ControllerB's index method? Then just do this.index(); since you're not wanting to call the superclass of someHandler you don't need the superclass call in there.

estesbubba
29 Nov 2011, 2:41 PM
That part works just fine. It's when I'm in ControllerA (which is an instance of ControllerB ) and call functionXYZ, that it calls the one in ControllerA and not ControllerB.

mitchellsimoens
29 Nov 2011, 4:17 PM
That's because the two are different classes. Are you instantiating both ControllerA and ControllerB and trying to call a method from ControllerB from ControllerA... or are you using ControllerA as an abstract and never instantiating it but only instantiating ControllerB?

estesbubba
29 Nov 2011, 4:47 PM
I'm only instantiating controllerB.

With Ext JS 4 controllerA was mixin for controllerB but we can't do that with Touch 1.1 so we tried using Ext.extend.