Terminology (created by me, but I think it explains well what is going on):

- |this| points to the object where property lookup starts. It always points to 
the beginning of the prototype chain.
- |here| points to the object where a property was found. |here| can point to 
any object in the prototype chain.

|super| starts property lookup in the prototype of |here|, but does not change 
|this|. That is, a method invoked via |super| still has the same |this| and 
property lookup via |this| is unchanged. If the super-method again uses 
|super|, then property lookup will begin in the prototype of |here| (= where 
the super-method has been found). Etc.

> From: Mariusz Nowak <[email protected]>
> Date: June 20, 2011 13:49:20 GMT+02:00
> Subject: Re: Making "super" work outside a literal?
> 
> It's most sane proposal I think. However few things are not obvious to me,
> will following evaluate as I assume:
> 
> var A = {
>       one: function () {
>               return 'A.foo';
>       }
> };
> var B = Object.create(A);
> 
> var C = Object.create(B);
> C.one = function () {
>       return super.one();
> };
> 
> var c1 = Object.create(C);
> obj.one(); // 'A.foo'

That would be c1.one(), right?

|here| === C and thus the search for super.one starts in B and finds A.one.

> B.two = function () {
>       this.three();
> };
> B.three =  function () {
>       return 'B.three';
> };
> C.two = function () {
>       super.two();
> };
> C.three = function () {
>       return 'C.three';
> };
> 
> var c2 = Object.create(C);
> c2.two();  // C.three

|here| === C and thus super.two === B.two

B.two() uses the original and unchanged |this| which is still c2.
=> this.three === C.three

SUMMARY: I agree with your findings.

-- 
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