Minimalist Classes
Dmitry Soshnikov
dmitry.soshnikov at gmail.com
Tue Nov 1 13:08:37 PDT 2011
On 01.11.2011 23:46, Allen Wirfs-Brock wrote:
>
> On Nov 1, 2011, at 12:27 PM, Jeremy Ashkenas wrote:
>
>> On Tue, Nov 1, 2011 at 3:21 PM, Axel Rauschmayer <axel at rauschma.de
>> <mailto:axel at rauschma.de>> wrote:
>>
>>
>> Another problem: What if an instance method makes a super-call?
>>
>> A slightly less elegant (and performant) variant of your solution
>> that works in both of the above cases is:
>>
>> - Keep track (per object and method) of the object where the
>> previous super-call (e.g. super.foo()) ended up.
>>
>> - Start your search either there or at |this|: look for the
>> *second* occurrence of property "foo". [optional: optimize
>> non-|this| case]
>>
>>
>> Nope -- I think that design isn't the correct semantics. super()
>> exists to delegate back to parent implementations of *the current
>> method*. When calling a different instance method the calls should
>> always start back out at the bottom of the inheritance hierarchy --
>> not at whatever level you happened to be on at the time.
>
> Who says? See
> https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp1.js#L419
>
>
> Note that this is a direct transliteration of code from one of the
> first and longest lived object-oriented class libraries (see comments
> at the head of the file). So super calls to "other methods" have a
> long history. It is a relatively rare technique, but sometimes it is
> essential. In this particular case, a super call to the same method
> would produce a loop. In this case choice of doing this.do and
> super.do needed to be made by the original programmer based upon their
> decomposition of methods.
>
Yes, I agree that ability to define own super method name is useful (and
some languages require it, even for constructors, e.g. Python).
However, another question I have. More often it's needed only to call
the parent method exactly with the same name. Can we may it's optional?
I mean, if syntactic for is super(...), then we take the name from the
caller function's name. Else, in case of super.foo(...) the name is
specified explicitly.
Dmitry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111102/608a0101/attachment-0001.html>
More information about the es-discuss
mailing list