View Full Version : Question about superclass and constructors

8 Dec 2009, 4:31 AM
While studying the tutorials and examples, I see that extending a class in Ext involves calling
parent methods (naturally). The pattern I invariably see is this:

Example: creating a subclass of panel:

var mypanel=function(cfg)
}There is something "not neat" in OO terms with this style of coding, IMHO, because the
new class is explicitly referenced by name in the inherited call. So, if the above code is cut&pasted, eg from a template snippet, it needs manual editing before it works. Consider, for example, a case where the "name" of the class , (mypanel), needs to be changed. one needs to edit ALL references to "mypane" and change them to the new name.

Coming from a strong OO background, I am more used to doing something like:

inherited constructor(args);
I set out to find a similar pattern in Javascript, just for cosmetics and "neatness" reasons.

First, I tried:

this.superclass.constructor.call(this,cfg);which would be the "natural" way of doing it.

This failed, of course, I think because "mypanel" refers to a constructor function, whereas "this" refers to the actual constructed object, not the same thing in Javascript.

Then, I tried this:

this.constructor.superclass.constructor.call(this,cfg);and this time, it seems it worked correctly.

So, my question:

is the latter form equivalent to the "usual" mypanel.superclass... pattern ?
if yes, is there a reason I should avoid using it?
if not, why aren't this syntax used in Ext ?