Making "super" work outside a literal?

Sean Eagan seaneagan1 at gmail.com
Wed Jun 22 08:09:18 PDT 2011


On Wed, Jun 22, 2011 at 9:23 AM, Axel Rauschmayer <axel at rauschma.de> wrote:
> From: Sean Eagan <seaneagan1 at gmail.com>
> Date: June 22, 2011 15:48:18 GMT+02:00
>
> There is no infinite recursion hazard in the semantics that Axel
> suggested, and that I used in the gist I posted
> (https://gist.github.com/1036200), where |super| is essentially the
> "the [[Prototype]] internal property of the object on which the method
> or accessor getter or setter was found"
>
> That would be the hypothetical "here".
>
> except that the |this| used in
> method calls and accessor getters and setters accessed from |super|,
> e.g. super.method() or super.accessorWithGetterOrSetterThatUseSuper,
> is the |this| of the caller, rather than the |super| of the caller.
>
> I don't think we need any "safety check" when assigning a method or
> accessor getter or setter that uses super to an object.  The concept
> of "super" seems to be a relative one, it is the object one step up in
> the prototype chain from the current object.  If a method or accessor
> getter or setter needs an *absolute* reference to the prototype of a
> given object, it should refer to it by name.
>
> The problem is that JS currently does not have the notion of the “current
> object”, it only briefly appears when looking for a property in the
> prototype chain.

ES does have a concept of "current object" or "object on which the
property was found", it's just implicit in the current spec.  In ES5,
prototype climbing occurs in 8.12.2 [[GetProperty]] (P) step 5.  The
"object on which the property was found" is just the "object on which
[[GetProperty]] found the property in step 1 (where it calls
[[GetOwnProperty]]).  I imagine that in reality [[GetProperty]] is
generally implemented iteratively rather than recursively for
performance reasons, in which case implementations would not need to
actually return the object up the "native call stack" or anything.

> "here" = object where a property was found is in general not the same as
> "this": "this" always points to the beginning of the prototype chain,
> whereas "here" can point to any of its members. E.g. when you invoke
>         var s = new String("abc");
>         s.trim();
> then "here" === String.prototype, but "this" === s. Otherwise
> String.prototype.trim() could not access the properties of s (such as
> s.length).

Right, |super| would be the [[Prototype]] internal property of the
|here| concept that you introduced.  As Brendan pointed out though,
|here| breaks abstractions, and is not a reserved word, so it should
not actually be exposed.

> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
> twitter.com/rauschma
> home: rauschma.de
> blog: 2ality.com
>
>
>



-- 
Sean Eagan


More information about the es-discuss mailing list