13.2.2 [[Construct]], constructor, and [[Class]] (was __proto__)

Brendan Eich brendan at mozilla.com
Fri Dec 14 13:08:18 PST 2007

On Dec 14, 2007, at 12:50 PM, P T Withington wrote:

> On 2007-09-23, at 14:14 EDT, Brendan Eich wrote:
>> The reason for the original prototype-owned constructor was to afford
>> a back-pointer from prototype to constructor function without
>> imposing a per-instance property (which could be optimized to be
>> shared where possible, overridden where desired -- but at some cost
>> in implementation complexity).
>> I'm not convinced it's worth changing this for ES4. Anyway it is very
>> late to have a new proposal -- we are finalizing proposals next week
>> at the face-to-face meeting.
> So, was nothing done about this?  We're starting to work on an es4
> back-end for our stuff and running into this issue.  We can make sure
> all our constructors give each instance a constructor slot (and we can
> smash the class prototype.constructor to point to the superclass) as
> we do for our es3 back end; but I was really hoping for a cleaner
> solution in es4.

Nothing's changed, no proposal that avoids per-instance overhead or  
more complicated implementation strategies to avoid that. There's  
also an entrainment hazard, not huge but non-zero risk of introducing  
leaks into existing web apps if we entrain the constructor where the  
web app code intentionally clears prototype.constructor (which is  

The constructor property is and always was intended to be a property  
of the prototype, not of each instance. Changing that now is hard.  
The merits are not compelling enough IMHO.

> Is there some other way in es4 that from an instance one can navigate
> up the superclass chain?  Can I say:
>    super.constructor
> perhaps, to find my class's superclass?

For a class C, C.prototype.constructor is indeed C. But super does  
not work that way -- it's used for invoking the super-class  
constructor, rather:

 >> class B { var x;function B(x) : x=x {} }
 >> new B(2).x
 >> class D extends B { var y; function D(x,y) : y=y, super(x) {} }
 >> d = new D(3,4)
[object D]
 >> d.x
 >> d.y

To reflect on inheritance and other relations, use the meta-objects  


Given class C:

let Ctype = reflect::typeOf(C);
for (let Csup in Ctype.superTypes()) {
     // Csup is a base class or interface of C here

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20071214/45254d21/attachment-0002.html 

More information about the Es4-discuss mailing list