PDA

View Full Version : callParent vs callSuper, understanding the hierarchy and potential



Csegota
14 May 2013, 2:46 PM
I'm currently working on upgrading some classes from Ext 3 to Ext 4. I am not the original author of these classes and after a brief introduction to Ext JS 4 was asked to dive right into the upgrading of this older application. I'm trying to wrap my head around just exactly how to use these two functions ( callParent vs. callSuper), which on the surface, seem very simple, but after digging around in the API docs I have been left with some questions.

Lets say I have a custom store, the layout and config doesn't really matter but it extends from Ext.data.Store
If I had a constructor in my custom store, and used callParent(args), this I believe would call the constructor of Ext.data.Store with the supplied arguments. Easy enough to understand.

Now when dealing with callSuper, if I called this in the constructor of my custom store I would assume that this would then call the constructor of the 'direct parent' of Ext.data.Store (which in my head I picture as 'up one level' from the parent, or what I picture as the same 'up TWO levels from my custom class (and this may be where my missunderstanding lays)), which as the API hierarchy would say is Ext.data.AbstractStore.

Now here is where my mind gets blown.

If you go to Ext.data.AbstractStore in the API, the first sentence reads as follows.
"AbstractStore is a superclass of Ext.data.Store (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store) and Ext.data.TreeStore (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.TreeStore)."

Am I insane or is AbstractStore the PARENT of Ext.data.Store... and NOT the superclass.
(my current understanding would lead me to believe that Ext.Base is the SUPERclass of data.Store (aka, up two levels))

So in my head I am understanding these two methods as follows:

callParent = go up one inheritance level and use that method
callSuper = to up TWO inheritance levels and use that method.
^^ I believe this is where my logic is flawed, for example, what if I had a class that was lets say '5 levels down' in inheritance (real abstracted thinking here) How would I call a method 4 or 5 levels 'up'. My mind is telling me this has to be done with recursion, but I cant wrap my head around it. for example, if it was done with recursion, that would mean that each method above my bottom/lowest level inherited class would have to use callParent, thus sending you recursively up the tree, but this would then force you to ALWAYS have to recurs to a specific method (the one that doesn't use callParent to send you up), basically overriding all methods that in fact have a callParent within them, and making that instance of the method inaccessible.

I'm not sure if this all makes complete sense but I think someone may be able to understand exactly what I'm getting at.

After rereading my post I had a potential epiphany . Does callSuper ALWAYS refer to the abstractClass of a hierarchy? this would potentially make this all make sense.

mitchellsimoens
16 May 2013, 5:13 AM
callSuper will call the overridden class' prototype method and skip any overrides. callParent will call the prototype method and execute all overrides also.