View Full Version : Better name for "this.callParent()"

Steffen Hiller
20 Feb 2011, 5:22 PM
This is a very frequently used method which got in my opinion an unfortunate name.

() already implies "call"ing something, so not sure why it has to be "call"Parent().
It just doesn't look beautiful. :)

My suggestions are:

I know that there have been reasons such as that parent is already used in another context in Ext and that super is a reserved word. (I also saw in the code that it was called "parent" before but is now deprecated.)

Either way, I think this method deserves a better name (and it's own thread). :-P

Btw, the method itself is awesome and probably my favorite addition to Ext 4, besides the theming stuff.

21 Feb 2011, 2:06 AM
I do not agree in this. A method should contain a verb.
For me, reading "this.parent" seems that you are invoking (http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.invoke) something.

21 Feb 2011, 3:35 AM
Super is out, as you mentioned it's a reserved word.
Parent is out because it could be used in a number of contexts (Element.parent() for one).

Base isn't bad, maybe a bit to "C#-ish"? I think my initial leaning is toward base over callParent, we'll see what others think.

21 Feb 2011, 3:38 AM
My suggestions are:

this.inherited() (in Dojo)

I agree with your suggestion. I like this.base() because it's short.

21 Feb 2011, 4:43 AM
for me it look strange to have
this.base() or simular, as this.base looks more like a property than a function. So i'm fine with callParent() or callBase().

Steffen Hiller
21 Feb 2011, 8:21 AM
Thanks for the comments!

Everyone has good points. :)

Just for the record I checked with other popular languages:
PHP uses parent::initComponent() (meh)
Java uses super.initComponent() (meh, not sure if you can use just "super" if it's the same method)
Ruby uses super (yeah) :-P

Regarding super:

Won't "super" be used as a keyword, just as "new"?
Really bad that we still can't use "super" or "new" as an object property. :(

The "only" problem I see is JSLint not validating it (which is a big problem, I know), but is JSLint right here?
This is really bad from the JSLint/ECMAScript side. :(

Let's see what others think.
I know this thread is a lot about taste, but maybe still interesting. :)

21 Feb 2011, 12:53 PM
hm... how about "_super" variable with "getSuper()" method?

Won't it be more flexible to grab hold of "parent"? what if I want to call different parent method?

Well I suppose, you can do this
MyClass.prototype._super = MySuperclass.prototype;

24 Feb 2011, 3:50 AM
Personally I think of the class you derive from as the base class, not a super class, and certainly not a parent; parent implies a container to me.

Yes, base is C sharpish, but then I have been writing C# for years...

I like the fact the method to forward to the base class has the verb 'call' in it, it tells you something.

I think I'd like a mixture please :)

How about, this.base is a property that provides you access to the base class instance, so can do this.base.getSomething(), say, but for forwarding to the base classes version of the current method I like this.callBase(arguments), rather than this.base.currentMethodName(arguments), since the method can and should be inferred from the context.

Just my two penneth.


24 Feb 2011, 4:03 AM
>> How about, this.base is a property that provides you access to the base class instance, so can do this.base.getSomething()...

... or optionally provide the name of the function to be called:

this.callParent("someMethod", arguments);

Steffen Hiller
24 Feb 2011, 5:32 AM
In Ext JS the "base class" always was referred to as "superclass", which is fine with me.

Hence, my latest idea:


24 Feb 2011, 5:46 AM
Why not callSuper()?