Re: es-discuss Digest, Vol 52, Issue 117
rauschma wrote: > > >> var c1 = Object.create(C); >> obj.one(); // 'A.foo' > > That would be c1.one(), right? > Yes, sorry edited post twice. rauschma wrote: > > > |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. > >From my perspective, this proposal looks perfect. I wouldn't look further :) - Mariusz Nowak https://github.com/medikoo -- View this message in context: http://old.nabble.com/Re%3A-es-discuss-Digest%2C-Vol-52%2C-Issue-117-tp31889060p31892405.html Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: es-discuss Digest, Vol 52, Issue 117
On Jun 20, 2011, at 2:51 PM, Peter Michaux wrote: > By the way, I like this idea that "super" is available all the time > (not just in an initializer) like "this" is always available; however, > adding another implicit variable "here" which is dynamic like "this" > is disconcerting as "this" has been quite a wild beast in JavaScript > to say the least. 'super' is not dynamic as proposed in http://wiki.ecmascript.org/doku.php?id=harmony:object_initialiser_super. Even in Allen's recent post about Object.defineMethod, 'super' is not bound dynamically per call site, as 'this' is. It's a hidden property of the function object. /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: es-discuss Digest, Vol 52, Issue 117
On Mon, Jun 20, 2011 at 1:27 PM, Axel Rauschmayer wrote: > 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. It doesn't seem quite right that an upward call like Object.getPrototypeOf(here).foo.call(this) has sugar super.foo() but sideways calls like here.foo.call(this) don't have any sugar. By the way, I like this idea that "super" is available all the time (not just in an initializer) like "this" is always available; however, adding another implicit variable "here" which is dynamic like "this" is disconcerting as "this" has been quite a wild beast in JavaScript to say the least. Peter ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: es-discuss Digest, Vol 52, Issue 117
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 > 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 a...@rauschma.de twitter.com/rauschma home: rauschma.de blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss