super.apply(this, arguments)

Graydon Hoare graydon at
Thu Dec 20 11:24:54 PST 2007

Peter Hall wrote:

> I haven't tried this in the RI, but what about:
>  var sup = super;
>  sup.apply(this, arguments);

No, the problem arises from two separate facts:

   - constructor invocation is not a function call
   - super-constructor chaining is not a function call either

Both of these are different operations with different semantics. We have 
a way of getting a function for the former (using the reflection API) 
such that you can run a constructor with variable args using apply. We 
do not have a way of getting a function for the latter, and really 
should not. Super-constructor chaining occurs only in a special, limited 
syntactic and semantic context: the end of the settings list, before the 
constructor body is entered. There's no reasonable interpretation of a 
first class escaping function that does this, as the context in which 
the function even makes sense vanishes as soon as the constructor body 
is entered. This is why we currently just use an explicit super-expression.

However, I think we can all see a nice symmetry argument that it would 
be nice to have an additional form for passing variable arguments up to 
your super-constructor. I'd imagine lots of possibilities might work, so 
long as they're unambiguous:

    function myObj(...args)
      : super.apply(args)          // a pseudo-property?

    function myObj(...args)
      : super_apply(args)          // a pseudo-global?

    function myObj(...args)
      : super_arguments = args     // a pseudo-local?

I suspect the first will turn the least number of stomachs, and is 
probably ok if we prohibit all *other* super-property accesses in the 
settings list. This seems plausible to me given that the first-class 
super rvalue hasn't even been initialized by the time the settings run, 
only allocated.


More information about the Es4-discuss mailing list