super.apply(this, arguments)
P T Withington
ptw at pobox.com
Thu Dec 20 11:29:35 PST 2007
Given that we already have a whacky syntax for calling the super
initializer (which I confess I had forgotten), why not allow apply
there? It's unambiguous there, since you are only allowed to call the
super initializer. This syntax is just letting you override how your
arguments are passed on to your super initializer. What is the
default if I don't specify a call to my super initializer? Does it
get all my arguments, or none of them?
class A extends B {
function A(x,y,z) : super.apply (this, arguments) { ... }
}
?
Personally, I really don't like the magic of the class name naming the
initializer. I would rather see a magic method name, say
`initialize`, so you say:
class A extends B {
function initialize(x,y,z) {
super.initialize.apply(this, arguments);
...
}
}
but that is probably too radical. On the plus side, you don't have to
repeat the class name, which makes easier maintenance and code reuse,
on the minus side there is a magic method name and you have to decide
whether to enforce arglist congruency or not (an issue hidden by
having each initializer have the class name as its name).
On 2007-12-20, at 13:05 EST, Jeff Dyer wrote:
> Sorry, I didn't mean to sound so flippant.
>
> As you may know, super expressions limit the binding of the name
> after the
> dot to the base class bindings. So the fragment above would call the
> super
> instance method 'apply', not the super constructor. We could give
> 'apply'
> some special meaning when the first argument is 'this', but the super
> constructor will have already been called during initialization.
>
> None of this means that the desired semantics wouldn't be possible to
> achieve with another syntax. My guess is that it would be somehow
> similar to
> the current super initializer syntax, which looks like this:
>
> class A extends B {
> function A(x,y,z) : super (x,y,z) { }
> }
>
> Suggestion welcomed.
>
> Jd
>
> On 12/20/07 9:04 AM, Dean Edwards wrote:
>
>>> On 12/20/07 7:20 AM, P T Withington wrote:
>>>
>>>> Ok. I didn't look in the wiki to start with because of that,
>>>> hence I
>>>> ask on the list: can I apply my super's constructor as in the
>>>> subject
>>>> line?
>>>>
>> Jeff Dyer wrote:
>>> Sorry, but you can't.
>>>
>>
>> That's a shame.
>>
>> -dean
>
More information about the Es4-discuss
mailing list