Making "super" work outside a literal?

Allen Wirfs-Brock allen at
Mon Jun 20 01:09:25 PDT 2011

I actually have a solution in mind for this.

Under the current proposal, a method containing super is "statically bound" to a specific object that provides the [[Prototype]] base for the "super" property lookup.  This is normally done by defining the method in the context of an object literal or class declaration.  If you want to define a method containing outside such a context you still need to provide the necessary binding.

What I have in mind is adding a reflection function for doing that:

let f= function () {return super.f()};
f();  //TypeError -- super unbound

let sup = {foo() {return "super hello"};
let sub = sup <| {};

Object.defineMethod(sub,"foo",f};   //adds f as property named "foo" of sub.  binds super for f

f(); // super hello

More information about the es-discuss mailing list