super, self, and sideways & durable vs. template

Peter Michaux petermichaux at
Sun Jun 12 16:29:56 PDT 2011

On Sun, Jun 12, 2011 at 2:17 PM, Brendan Eich <brendan at> wrote:
> On Jun 12, 2011, at 1:00 PM, Peter Michaux wrote:
>> Something I try to do when designing constructors is to ensure the
>> constructed objects will be durable. That is, if some code modifies or
>> breaks parts of the constructed object's exposed interface, the other
>> parts of the exposed interface should continue working the same as
>> before.
> The flip side of "brittle" is "extensible": subclasses might break the base class, or they might usefully extend it. Some cases may need to delegate to the subclass (a la virtual in C++).

Yes the extensibility of the template pattern is worth mentioning. The
nice part of the closure system with its sideways calls is that it
naturally allows control of when a method can be overridden in the
template style and when it cannot.

>> My primary reason for asking here is I'm curious if there is any
>> allowance for sideways calls in the proposed class syntax. By that I
>> mean using the prototype parts of the proposed syntax rather than the
>> closure based parts of the syntax (since the syntax can do both.)
> Just to be clear to everyone following, you could use the closure pattern as Mark showed, for sure.

Yes. It seems that the major objection to the closure system is
"efficiency". In the tradeoffs, some people weigh the extra memory
and/or extra construction time heavily enough that the closure system
does not appeal to them despite its other benefits. I'm trying to
understand if the prototype side of the class proposal can do it all.

> If you wanted to expose log on the prototype, you'd need:
> class Monster {
>  ...
>  function log( { /*...*/}
>  log = log;
>  attack(target) {
>    log('The monster attacks ' + target);
>  }
> }

If the log function is going to use the data of the object then does
it require binding "this"?, 'The monster attacks ' + target);


More information about the es-discuss mailing list