Making "super" work outside a literal?

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Sat Jun 25 14:01:07 PDT 2011


On 26.06.2011 0:49, Brendan Eich wrote:
> On Jun 25, 2011, at 11:13 AM, Axel Rauschmayer wrote:
>
>> I don’t know if this has been discussed, but I find the |super| work-around provided by YUI and CoffeeScript (in the generated code) not that bad:
>>
>>         ThisClass.__super__.foo.call(this, arg1, arg2);
> I'm not sure what you mean. If we add 'super', surely we want more than the __super__ hack. We also want a callable expression 'super' in constructors, and a 'super.foo' form for method and other property accesses from subclass methods. We don't want people writing out .call by hand.
>
>

Apologize in advance if I'm mentioning already discussed thing in these 
classes-related topics (unfortunately hadn't enough of time to read them 
all and follow), but from what I can say, people want to write also and 
_mostly_ _just_ `super`, not even `super.foo` (though, of course 
`super.foo` notation would be also nice to have -- to be able to call 
_any_ parent method).

Again, we even _now_ (vis simple JS class-library) can write normal 
`this.super(...)` calls from _any_ descendant method (and could even in 
ES3 era, though, via `this._super(...)`) -- that is without specifying 
exact parent name (i.e. `super.foo`) which in case of the same method is 
just again is the syntactic noise. So it's important thing to have 
_just_ super(...) -- if it's a sugar, let it be really the sugar 
(because if not, why do I need it at all if I can achieve even better 
with a library?). And _in addition_ -- super.otherMethodName notation.

Dmitry.

>> With ThisClass.__super__ pointing to SuperClass.prototype.
> The CoffeeScript compiler can lexically bind ThisClass and wire up __super__ with generated runtime helper code. That's all backstage of the CoffeeScript *language*, though.
>
>
>> As a completely static solution, one could maybe expand a super-call
>>         super.bar(x, y);
>> to
>>         __CurrentObject__.[[Prototype]].bar.call(this, x, y);
>>
>> On the other hand, I don’t know if a reference to __CurrentObject__ is ever available for some kind of static expansion.
> Are you talking about |here| again, with a new name? There is no static counterpart other than the one Allen proposed, the object literal directly containing the method that uses 'super'.
>
> /be
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list