Making "super" work outside a literal?

Juan Ignacio Dopazo dopazo.juan at gmail.com
Wed Jun 22 12:16:33 PDT 2011


On Wed, Jun 22, 2011 at 3:01 PM, Sean Eagan <seaneagan1 at gmail.com> wrote:

> On Wed, Jun 22, 2011 at 12:07 PM, Juan Ignacio Dopazo
> <dopazo.juan at gmail.com> wrote:
> > Can the value of a dynamic super be unambiguously resolved with prototype
> > climbing and without an extra implicit parameter?
>
> Yes, it can be unambiguously determined by prototype climbing, the
> only information from the call site that is used is the base ( |this|
> ) value of the method call or accessor property access, whose
> prototype chain is the one that is climbed.
>
> Cheers,
> Sean Eagan
>

If I understood correctly this thread, the problem seems to be in
distinguishing between |this| and the prototype that "owns" the function.
Let me see if I can explain it...

var A = {
  method: function () { /* do something */ }
};

var B = Object.create(A);
B.method = function () {
  Object.getPrototypeOf(this).method(); // if you do this, then in the
context of A.method |this| will be A, not B
  Object.getPrototypeOf(this).method.call(this); // if you do this, then
it's all ok unless you want add another level
};

var C = Object.create(B);
C.method = function () {
  Object.getPrototypeOf(this).method.call(this); // Now in B.method |this|
will be C and getPrototypeOf will be used with C... an infinite loop
};

IIRC, this is why a |here| value is needed.

Juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110622/b8fb2315/attachment.html>


More information about the es-discuss mailing list