On May 31, 2012, at 1:54 PM, Allen Wirfs-Brock wrote:
> On May 31, 2012, at 1:53 AM, Herby Vojčík wrote:
>> reacting to "super only in classes", I'd like to propose widening it just a little bit:
>> 1. Allow super in every concise methods (in classes, as well as out of them).
> Basically this means in object literals (or object extension literals if we have them)
It still seems to me that the majority of the time, super used in an object literal will not actually behave correctly. My pushback on a general notion of super outside of classes is based on the assumption that it will be a misleading feature, suggesting support for super calls in many places there actually is not.
In fact, without <|, are there any cases where super behaves correctly in an object literal, other than making super calls to Object.prototype functions?
Take Backbone/Underscore as an example. A developer writes some code like:
They rightly think they can use a super call inside an object literal. But it doesn't behave correctly, because extend is ultimately (somewhere in code that the end-developer shouldn't really need to be aware of) implemented in just the simple ES3-compatible way:
As I understand it, super will not work correctly in cases like these unless the authors of every object model library opt in to taking an ES6 dependency on Object.defineMethod, or fork their implementations to detect and behave differently on ES6. I believe the necessary change to these APIs is intended to be something like this - but I'm pretty sure this also wouldn't be correct, because it rebinds the super bindings of functions which may have been correctly bound previously to other points in the prototype hierarchy.