> On 25 oct. 2011, at 11:03, Nathan Appere wrote:
>
> I've encounter a behaviour that I cannot quite explain when dealing with
> prototype.
> In most of the articles I've read on the subject, you find something like:
> (this is taken from Resig inheritance model)
>  // Populate our constructed prototype object
>  Class.prototype = prototype;
>
>  // Enforce the constructor to be what we expect
>  Class.prototype.constructor = Class;
>
> It seems to me that the second instruction does nothing.

On Tue, Oct 25, 2011 at 3:54 PM, Alexandre Louis Marc Morgaut
<[email protected]> wrote:
> It makes the code
> a instanceof B
> return true

Ehm, no, that's what setting prototype is for. instanceof will ONLY
use the prototypal chain. So that means the magic child.[[Prototype]]
-> parent.prototype link. Or in some browsers, child.__proto__ ->
parent.prototype (note: [[Prototype]] is only for the specification,
but __proto__ exposes it anyways and is regarded as the same thing;
the link from the child to the parent prototype object). That's the
only chain that matters for instanceof and inheritance. So instanceof
doesn't care about .constructor, in fact nothing does. Browsers will
set it so libraries mimic that behavior.

The specification doesn't even mention the property (I just checked to
make sure).

- peter

-- 
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