Making "super" work outside a literal?

Brendan Eich brendan at mozilla.com
Sat Jun 25 14:06:44 PDT 2011


On Jun 25, 2011, at 2:01 PM, Dmitry A. Soshnikov wrote:

> 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).

In a constructor, calling super calls the super-constructor. No need for super.constructor() or whatever.

Unlike CoffeeScript, which allows a method foo to super-call only the method of the same name in the superclass, the ES.next proposals I've seen want super.foo(). This allows super.bar() from method foo of a subclass, where the superclass bar might of course loop around and call the superclass foo.

> 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.

For some reason I missed this Ruby-ish notion of super-method calling, which CoffeeScript supports. It is not what the ES.next proposals require for a super-method call. See

http://wiki.ecmascript.org/doku.php?id=harmony:classes#member_delegation

We should discuss this more concise 'super'-only, not 'super.foo' idea. Is it only for conciseness, or is the fact that it does not support 'super.bar' from within a method named 'foo' important?

/be



More information about the es-discuss mailing list