Minimalist Classes

Jeremy Ashkenas jashkenas at gmail.com
Tue Nov 1 11:48:28 PDT 2011


On Tue, Nov 1, 2011 at 2:21 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

> Invocation: B.describe.call(obj) should return "BA". With your library I
> would expect it to return "BBA".
>

Yes, it would. That's a good tricky case. I'm not sure if extra bookkeeping
could make sense of that call, as there isn't any information as to where
the function fits in to obj's prototype chain -- or if it's part of another
prototype chain entirely. I'd like to hope that something could be figured
out, but another alternative is for super() within a direct call() or
apply() to be an error.


> Would obj.one() work? As far as I can tell, your bookkeeping works for one
> super recursion only, not for two.
>

Yes, obj.one() would work. You can keep track of the super() depth
per-object-per-method ... and even for fancier cases where you restart the
same super() chain recursively from the outside. Imagine if one of the
deeper super.one()'s itself calls obj.one(), with a direct reference to the
instance (and a different parameter, to avoid infinite recursion). You can
imagine super counters as a stack instead of a value, and push a fresh one
on, popping it when the new obj.one() call exits.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111101/71d0b7e1/attachment-0001.html>


More information about the es-discuss mailing list