I've encounter a behaviour that I cannot quite explain when dealing with prototype.
 // 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.

The comment has the explanation: there is a convention about
what .constructor is pointing to. If nobody is ever going to look
at the property, it doesn't matter if that convention is broken,
but it is easier to maintain the convention than to prove that
nobody is ever going to look at the property.

(I think "Eloquent Javascript" mentions this kind of thing)

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

To clarify: the instanceof spec doesn't mention .constructor.
The Ecmascript spec as a whole does mention initial values
for .constructor for the built-in objects (15.*), and for creating function objects (13.2). There do not seem to be any specified
uses of the property, nor can there be many guarantees about
its value, but the examples set an expectation.

(since reading the spec is useful: http://www.ecmascript.org/ )

Claus


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