On Fri, Sep 30, 2011 at 9:01 PM, Oliver Hunt <oli...@apple.com> wrote:
> Imagine
>
> class Foo {
>   function name() {
>         return "foo"
>   }
> }
>
> class Bar : Foo { // s/:/extends or whatever
>   function name() {
>         super.name();
>   }
> }
>
> class Wibble : Bar {
>   function name() {
>         super.name();
>   }
> }
>
> the call to super.name() essentially desugars to:
>
> this.__proto__.name.call(this, ...)
>
> But this.__proto__ will be the same everywhere, so someWibble.name() will 
> infinitely recurse when it reaches Bar::name
>
> Hope this helps.

Eventually, yes thanks. (Assuming I am translating the stuff above correctly).

If we try to use this.__proto__ in some JS like the stuff above we get
a call to missing method.

someWibble.name() calls Wibblle.prototype.name with |this| bound to
someWibble. someWibble.__proto__ points to Bar.prototype that's good.
But Bar.prototype.__proto__ points to Object, not Foo. So when we try
to recurse in bar with
   return this.__proto__.name();
then |this| is a Bar.prototype, not the result of new Bar().

Of course we just use
  Bar.prototype.name = function() {
    return Foo.prototype.name()
  }
now instead.

jjb

>
> --Oliver
>
> On Sep 30, 2011, at 7:38 PM, John J Barton wrote:
>
>> On Fri, Sep 30, 2011 at 5:47 PM, Axel Rauschmayer <a...@rauschma.de> wrote:
>>>
>>> Isn't it just a matter of referring to the property with "super"?
>>> class Pirate {
>>>   get name() {
>>>     return "Captn' " + super.name;
>>>   }
>>> }
>>
>> just trying to understand: how is super different from __proto__?
>> jjb
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to