On Oct 2, 2011, at 1:55 , Lasse Reichstein wrote:

> On Sat, Oct 1, 2011 at 5:36 PM, Axel Rauschmayer <[email protected]> wrote:
> > Am I right that super-calls only works for class methods, because they know 
> > the, statically determinable, prototype chain of its instances, and 
> > therefore it knows where to start the search.
> 
> Yes that’s a tricky problem. There are two solutions:
> 
> 1. Keep a dynamic variable "here" (similar to "this") that is filled in when 
> invoking the method. You have to traverse the prototype chain to find the 
> method and thus know which object it is in. Advantage: robust with regard to 
> dynamic changes to properties. Disadvantage: high cost, even for methods that 
> don’t use "super" (and it won’t be that frequently used a feature).
> 
> That's the solution I could see, if it is going to work dynamically.
>  
> 2. Statically store in methods what object they come from. This works best 
> with object literals. Consult [1] for the details – it’s an internal property 
> called [[Super]]. In theory, one could also have a property [[Here]], to 
> support accessing sibling properties, but with modules, I don’t think that is 
> a frequent use case. If one uses an object literal for modularity, one has to 
> be careful *not* to use "this" to access siblings.
> 
> That sounds like it would trip up reusing functions across different objects. 
> If I define a function outside of any object, and then assign it to two 
> different functions' prototypes, it's not a property of the function what 
> "super" should refer to - if it should work in any predictable way.
> 
> I'm not too fond of implicitly or automatically binding functions. 


It’s a performance thing support for dynamic "super" would slow everything down 
and is thus not worth it. In the current spec, there is a method for moving 
methods with "super" from one object to another. It’s not as elegant, but given 
the performance cost of dynamic "super", it’s the right call.

Details in this thread:
https://mail.mozilla.org/pipermail/es-discuss/2011-June/015334.html

Axel

-- 
Dr. Axel Rauschmayer

[email protected]
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to