Hi,
> why not just use this.superclass.method in the subclass?
If you mean:
this.superclass.method(arg);
...there are a couple of problems there. The first, which could easily
be fixed, is that the above would lose the meaning of `this` within
the call to the parent method. To preserve it, you'd need to do this:
this.superclass.method.call(this, arg);
But that won't work either, because there is no
`this.superclass.method` available (in fact, no `this.superclass`)
within the code of an instance's method: http://jsbin.com/uhitu5
The closest to `this.superclass.method` you can come is:
this.constructor.superclass.prototype.method.call(this, arg);
...which works (http://jsbin.com/uhitu5/3) but I think you'd agree is
fairly long-winded. :-) (It also assumes nothing writes to the
`constructor` property, which is *probably* a valid assumption, and
yet...)
Or you could constantly reiterate the name of your class:
ThisClass.superclass.prototype.method.call(this, arg);
...which also works (http://jsbin.com/uhitu5/2) but makes it a pain to
rename your class.
Or reiterate the name of your parent class:
ParentClass.prototype.method.call(this, arg);
...which also works but makes it a pain to rename the parent class or
rebase your class.
Regardless, compared with Prototype's magic
$super(arg);
...even the most terse of the above is verbose. :-)
Prototype's magical `$super` comes at a marked runtime cost -- not
that it usually matters -- and relies on unstandardized behavior
(function decompilation), which is probably more of a concern (as it's
known not to work on some mobile browsers). I did an alternate
mechanism that's more efficient and doesn't rely on function
decompilation, but at the cost of adding slightly to the complexity of
making the call:
method.$super.call(this, arg);
or with a helper method (which is added overhead):
this.callSuper(method, arg);
Details here, it may be useful reading for your thesis (or not):
http://blog.niftysnippets.org/2009/09/simple-efficient-supercalls-in.html
HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com
On Mar 18, 1:13 pm, Luke <[email protected]> wrote:
> I'm sorry, what I meant was this.superclass In Prototype's class
> implementation you can see that if you provide a parent-class in prototype's
> Class.Create-Method, that class will be referenced as superclass in the
> class you are creating:
>
> function create() {
> var parent = null, properties = $A(arguments);
> if (Object.isFunction(properties[0]))
> parent = properties.shift();
>
> // ...
>
> klass.superclass = parent;
>
> // ...
>
> return klass;
> }
>
> why not just use this.superclass.method in the subclass?
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.