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

Brendan Eich brendan at mozilla.org
Sun Sep 23 11:14:47 PDT 2007

On Sep 23, 2007, at 8:59 AM, liorean wrote:

>> 1. The constructor property should be on the object instance  
>> *created*
>> by the function.
> That argument I agree with. It should be on the instance and not  
> the prototype.

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.

> On 23/09/2007, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
>> 2. (new function(){}).constructor should be Function.
> I agree. And in ES3 it is, unless the function either:


js> (new function(){}).constructor
function () {
js> function C(){}
js> new C().constructor
function C() {

in no case is the value of (new function(){}).constructor Function.

> - Returns another object than that it was passed from [[Construct]]
> - Creates a constructor property on the this object that is not a  
> function
> - Has it's prototype overwritten

Good points.

> But for ES3 and real web compatibility, I don't think changing the
> algorithm to not allow ordinary ES3 functions used as constructors to
> return objects other than the one set up by [[Construct]] will work.

Right, this will break the web. Tucker can weigh in on the  
workarounds OpenLaszlo needed to cope with the instance of this bug  
in Flash (AS2, and I think AS3 still, do not let a function return a  
different object from the one passed in as this when called via new).

>> ES4 ref impl seems a bit off:
>>>> (new function F(){}).constructor
>> [function Function]

This is on file: http://bugs.ecmascript.org/ticket/64

>>>> new Date(9e9).constructor
>> [class Class]

I don't see this one on file -- someone please file it! Thanks.

>>>> 1['constructor']
>> [class Class]
> Seems a bit broken, yes...

This one may be covered by other tickets but filing it won't hurt.

>> It appears that es4 ref impl has the correct result for instancof  
>> on primitives
>> All are true in ES4 and false in ES3:
>> true instanceof Boolean
>> "oo" instanceof String
>> 2 instanceof Number
>> null instanceof Object
>> NaN instanceof Number
>> Number.Infinity instanceof Number
>> I think the change is correct. if typeof b == "boolean", b instanceof
>> boolean seems like it must be true.
> A bugfix, IIRC.

Incompatbile enough that we are not taking the chance -- we are  
changing this to match ES1-3, and to avoid boolean <: Boolean etc.


More information about the Es4-discuss mailing list