On 3 November 2011 10:35, Asen Bozhilov <[email protected]> wrote:

> Nick Morgan:
>
> > Now, if you do this instead:
> >
> >     Ctor.prototype = null;
> >
> >     var y = new Ctor;
> >
> >     y.toString;
> >     => function ...
> >
> > Here's a fiddle that illustrates the above:
> > http://jsfiddle.net/skilldrick/gabEN/
> >
> > So, how is `toString` looked up on `y`? Is there a special case when the
> > constructor's prototype property is null, or am I misunderstanding
> > something?
>
> You should look at 13.2.2 [[Construct]].
> 1. Let obj be a newly created native ECMAScript object.
> ....
> 4. Let proto be the value of calling the [[Get]] internal property of
> F with argument "prototype".
> 5. If Type(proto) is Object, set the [[Prototype]] internal property
> of obj to proto.
> 6. If Type(proto) is not Object, set the [[Prototype]] internal
> property of obj to the standard built-in Object prototype object as
> described in 15.2.4.
>
> So when you do:
>
> new Ctor;
>
> According step 6 you will get object which prototype chain should look as:
>
> instance obj -> Object.prototype -> null
>
>
Ah, interesting. So, if I understand it correctly if you set
constructor.prototype to null (or *anything* non-object), you're just
losing a step on the chain:

instance obj -> Object.prototype -> null

instead of:

instance obj -> {} -> Object.prototype -> null

Cheers!
-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick

Save our in-boxes! http://emailcharter.org

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to