Making "super" work outside a literal?

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Jun 20 02:22:00 PDT 2011


with corrections below:

On Jun 20, 2011, at 9:09 AM, Allen Wirfs-Brock wrote:

> 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 super 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 "sub-"+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
> 
> sub.f(); // sub-super hello
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list