Minimalist Classes
Axel Rauschmayer
axel at rauschma.de
Tue Nov 1 10:34:27 PDT 2011
If you have a prototype chain of objects, |this| will always point to the beginning of the chain (which is also where properties are created whenever you set a property via |this|). This is what allows methods in the prototype to access instance properties.
If there is a method m in any of the objects of the chain and it makes a super-call, you want the search to start in the prototype of m’s object – and not in the prototype of |this| (which is always the second object in the prototype chain).
Does that make sense?
On Nov 1, 2011, at 18:22 , John J Barton wrote:
> On Tue, Nov 1, 2011 at 9:45 AM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>>
>> On Nov 1, 2011, at 6:53 AM, Jeremy Ashkenas wrote:
>
>> The complication of super is that each "super call" requires two independent
>> pieces of state in additional to the method arguments: the object that will
>> be used as the |this| value of the resulting method invocation and the
>> object where property lookup will begin when searching for the method.
>> Let's call this the "lookup-point". |super| when used to access a method
>> property really represents a pair of values (this,lookup-point). In the
>> general case, these are not the same value so they must be independently
>> captured and represented.
>> Where do these two pieces of state come from? The |this| value of a super
>> call is simply the |this| that was dynamically passed into the calling
>> method. Where does the look-up point come from. There are fundamentally
>> two possibilities:
>> a) it is dynamically passed to every method invocation, ;just like |this|
>> currently is
>> b) it is statically associated with the method in some way.
>
> I'm just curious and I think understanding the following point would
> help developers:
>
> Why isn't the |super| lookup-point |this.getPrototypeOf()| (The
> protolink or [[Prototype]])? I thought that if
> let f = new F();
> and F inherits from G, then f.foo() will have this.getPrototypeOf()
> === G and that is what super would be? Somewhere I went wrong...
>
> jjb
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
--
Dr. Axel Rauschmayer
axel at rauschma.de
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111101/aa3d7479/attachment.html>
More information about the es-discuss
mailing list