13.2.2 [[Construct]], constructor, and [[Class]] (was __proto__)
Garrett Smith
dhtmlkitchen at gmail.com
Sun Sep 23 12:22:55 PDT 2007
On 9/23/07, liorean <liorean at gmail.com> wrote:
> > > On 23/09/2007, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
> > >> 2. (new function(){}).constructor should be Function.
>
> > On Sep 23, 2007, at 8:59 AM, liorean wrote:
> > > I agree. And in ES3 it is, unless the function either:
>
> On 23/09/2007, Brendan Eich <brendan at mozilla.org> wrote:
> > No:
> >
> > js> (new function(){}).constructor
> > function () {
> > }
> > js> function C(){}
> > js> new C().constructor
> > function C() {
> > }
>
> Ah, my mistake there, was thinking of (function(){}).constructor for a
> moment there.
>
>
> > in no case is the value of (new function(){}).constructor Function.
>
It shouldn't be, but it is in OSX Ref Impl. (I did not build this).
js> (new function(){}).constructor
[function Function]
> Thinking about it with the new keyword in mind, I just realise that
> what Garrett suggested makes no sense anyway - the function object is
> the constructor. The function object is an instance of Function, but
> the resulting object is an instance of the function object. Making the
> object have Function as it's constructor property breaks the
> prototype-constructor relationship.
>
>
Correctly corrected.
In the following example:
function F(){}
F.prototype.constructor = F;
F.prototype.propertyIsEnumerable("constructor"); // false, it's set to
{DontEnum} in step 10. Object.prototype.
F.prototype.constructor === F; //true
F.prototype = {
constructor : F
};
F.prototype.constructor === F; // false
F.prototype.propertyIsEnumerable("constructor"); // true, now
F.prototype is an object
F.prototype is assigned to a new Object. The new Object goes through
[[construct]] getting its [[class]] property to Object. Object
instances get the constructor property from Object.prototype. The only
exception being prototype properties of Function objects, where the
constructor is flagged DontEnum.
The constructor property of an object doesn't reflect the constructor
that called it.
Garrett
> > > On 23/09/2007, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
> > >> It appears that es4 ref impl has the correct result for instancof
> > >> on primitives
>
> > On Sep 23, 2007, at 8:59 AM, liorean wrote:
> > > A bugfix, IIRC.
>
> On 23/09/2007, Brendan Eich <brendan at mozilla.org> wrote:
> > Incompatbile enough that we are not taking the chance -- we are
> > changing this to match ES1-3, and to avoid boolean <: Boolean etc.
>
> Sad to hear that, but I guess compatibility will have to rule here.
So it's going back, to (true instanceof Boolean == false), huh ?
> --
> David "liorean" Andersson
More information about the Es4-discuss
mailing list