Making "super" work outside a literal?

Sean Eagan seaneagan1 at
Thu Jun 23 07:14:42 PDT 2011

On Thu, Jun 23, 2011 at 4:56 AM, Allen Wirfs-Brock
<allen at> wrote:
> If you don't have actual implementation experience with dynamic languages I
> think you guys will just have to take Brendan's and my word for this.

I now understand and fully agree with your performance arguments
against dynamic super.  However, I still believe that the dynamic
super semantics are largely superior to the static super semantics.

Fortunately, I think the dynamic super semantics can be simulated via
static super, thus yielding the best of both approaches!

Here's what I propose:


super function - a function that uses |super|
super delegate function - A function which delegates to a super
function stored in its [[SuperFunction]] internal property, passing a
|super| binding stored in its [[Super]] internal property.


When a super function is assigned as a method or accessor getter or
setter either via an object literal, Object.defineProperty or direct
assignment, a super delegate function is created and assigned instead
whose [[SuperFunction]] internal property is the super function being
assigned, and whose [[Super]] internal property is the [[Prototype]]
internal property of the object being assigned to.

When a super delegate function is subsequently accessed from an
object, e.g. o.methodThatUsesSuper or
"accessorWithGetterOrSetterThatUsesSuper"), this resolves to the
[[TargetFunction]] internal property of the super delegate function.

When a super function is called directly, e.g. superFunction() or, |super| is resolved as the [[Prototype]]
internal property of the |this| of the call.

When a super delegate function is called, e.g.
o.methodThatUsesSuper(), o.accessorWithGetterThatUsesSuper, or
o.accessorWithSetterThatUsesSuper = "foo", |super| is bound to the
super delegate function's [[Super]] internal property.

The equivalence class of a super function in  == and === consists of
the super function and all of its corresponding super delegate
functions, to illustrate:

let f = function(){return super.x},
    o1 = {method: f},
    o2 = Object.create(null, {method: {get: f}});
assert(f === o1.method); // true
assert(o1.method === Object.getOwnPropertyDescriptor(o2, "method").get); // true

Thus, the static super implementation is completely abstracted from
the user, and they benefit from the full dynamic super semantics!

I'm sure there are still details to work out, but it seems quite
promising to me.

Sean Eagan

More information about the es-discuss mailing list