Making "super" work outside a literal?

Axel Rauschmayer axel at rauschma.de
Wed Jun 22 07:23:40 PDT 2011


> From: Sean Eagan <seaneagan1 at gmail.com>
> Date: June 22, 2011 15:48:18 GMT+02:00
> 
> There is no infinite recursion hazard in the semantics that Axel
> suggested, and that I used in the gist I posted
> (https://gist.github.com/1036200), where |super| is essentially the
> "the [[Prototype]] internal property of the object on which the method
> or accessor getter or setter was found"

That would be the hypothetical "here".

> except that the |this| used in
> method calls and accessor getters and setters accessed from |super|,
> e.g. super.method() or super.accessorWithGetterOrSetterThatUseSuper,
> is the |this| of the caller, rather than the |super| of the caller.

> I don't think we need any "safety check" when assigning a method or
> accessor getter or setter that uses super to an object.  The concept
> of "super" seems to be a relative one, it is the object one step up in
> the prototype chain from the current object.  If a method or accessor
> getter or setter needs an *absolute* reference to the prototype of a
> given object, it should refer to it by name.

The problem is that JS currently does not have the notion of the “current object”, it only briefly appears when looking for a property in the prototype chain.

"here" = object where a property was found is in general not the same as "this": "this" always points to the beginning of the prototype chain, whereas "here" can point to any of its members. E.g. when you invoke
        var s = new String("abc");
        s.trim();
then "here" === String.prototype, but "this" === s. Otherwise String.prototype.trim() could not access the properties of s (such as s.length).

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



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


More information about the es-discuss mailing list