> From: Quildreen Motta <[email protected]>
> Subject: Re: Super-calls
> Date: October 4, 2011 1:19:33 GMT+02:00
> To: [email protected]
>
>
> On 03/10/11 19:49, Erik Arvidsson wrote:
>> On Mon, Oct 3, 2011 at 14:50, Axel Rauschmayer<[email protected]> wrote:
>>> 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.
>> I'm not sure it is just a performance issue. I believe the semantics
>> is wrong too.
>>
>> class B {
>> a() {
>> this.b();
>> }
>> b() {
>> print('B.b');
>> }
>> }
>>
>> class C extends B {
>> a() {
>> super.a();
>> }
>> b() {
>> print('C.b');
>> }
>> }
>>
>> var c = new C;
>> c.a(); // Should print 'C.b'
>>
>> With a dynamic super the above would lookup b in the wrong object
>> (B.prototype instead of C.prototype)
>
> The problem then, with dynamic super, becomes that one needs to pass the
> called method a hint of what the next object in the prototype chain is, since
> we can't use `this' — it'll always be the same in all methods called through
> `super'.
>
> Static super solves that problem by placing that information directly in the
> method, so it's just a lookup away. Dynamic super solves that problem by
> passing the information as an implicit parameter to *every* function call,
> just like `this', thus being a perf problem.
Correct, with a dynamic super, you keep track of "here" while doing the method
lookup, with static super, you hardcode (which is fine, unless you move the
method).
Thus, statically, the code above is rewritten as follows:
class B {
a() {
this.b();
}
b() {
print('B.b');
}
}
class C extends B {
a: function func() { // C.prototype.a.[[Super]] = B.prototype (assigned
statically)
func.[[Super]].a.call(this);
},
b() {
print('C.b');
}
}
super being rare and moving methods being rarer, I think the tradeoff for
performance is OK, especially as there will be a method that allows you to move
methods. If performance wasn’t an issue, dynamic "super" would be preferable.
--
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