The Constructor Of Object.prototype
Solution 1:
From "this and Object Prototypes" book of "You don't know JS" series by Kyle Simpsion
functionFoo() {
// ...
}
Foo.prototype.constructor === Foo; // truevar a = newFoo();
a.constructor === Foo; // trueThe
Foo.prototypeobject by default (at declaration time on line 1 of the snippet!) gets a public, non-enumerable (see Chapter 3) property called.constructor, and this property is a reference back to the function (Foo in this case) that the object is associated with. Moreover, we see that objectacreated by the "constructor" callnew Foo()seems to also have a property on it called.constructorwhich similarly points to "the function which created it".Note: This is not actually true. a has no
.constructorproperty on it, and thougha.constructordoes in fact resolve to theFoofunction, "constructor" does not actually mean "was constructed by", as it appears. We'll explain this strangeness shortly....
"Objects in JavaScript have an internal property, denoted in the specification as [[Prototype]], which is simply a reference to another object.".
So, Object.prototype itself is not an object. As to your specific question about instanceof:
var a = newFunction();
a.prototypeinstanceofObject; //truevar b = newString();
b.prototypeinstanceofObject; //false
Post a Comment for "The Constructor Of Object.prototype"