Hello Amit,
> 1) newtoy.constructor.prototype.constructor.prototype.constructor.prototype > = ?? > The answer is `Gadget.prototype`. When function objects are created<http://ecma262-5.com/ELS5_HTML.htm#Section_13.2>, the property named `prototype` is defined on the function object, the value of this property is a simple empty object (as if it were created by the expression `new Object()`). After that, the `constructor` property is defined on this new object, and it just points back to the original function object. Basically, the property `Gadget.prototype.constructor` holds a reference to the `Gadget` function itself, that's why we get `Gadget.prototype` at the end. 2) newtoy.__proto__.__proto__.__proto__ = ?? > The answer is `null`. The non-standard `__proto__` property allows you to access the internal [[Prototype]] property of objects, in the case of `newtoy`, an object that was created using your `Gadget` constructor, has two objects in his *prototype chain*, at first `Gadget.prototype` (newtoy.__proto__) and then `Object.prototype` (newtoy.__proto__._proto__). The prototype chain of `newtoy` looks something like this: newtoy --> Gadget.prototype --> Object.prototype --> null Accessing a property that is not physically defined on an object, will start a lookup on objects higher in the prototype chain, in order to resolve the value of the property being accessed, for example: newtoy.hasOwnProperty('rating'); // false, not an own property 'rating' in newtoy; // true, inherited from Gadget.prototype newtoy.rating === Gadget.prototype.rating; // true newtoy.hasOwnProperty('toString'); // false, not an own property 'toString' in newtoy; // true, inherited from Object.prototype newtoy.toString === Object.prototype.toString; // true Also, you can see that those objects are on the prototype chain of `newtoy`, e.g.: Gadget.prototype.isPrototypeOf(newtoy); // true Object.prototype.isPrototypeOf(newtoy); // true // Or, since we have constructors: newtoy instanceof Gadget; // true newtoy instanceof Object; // true `Object.prototype` is on the prototype chain of this `newtoy` object because as I said in the first question, the value of the `Gadget.prototype` property, is a reference to an object as if it were created by the expression `new Object()<http://ecma262-5.com/ELS5_HTML.htm#Section_15.2.2.1>`, created at the time the `Gadget` function was defined, and an object built in this way, inherits from `Object.prototype`. At the end we get `null`, because `Object.prototype<http://ecma262-5.com/ELS5_HTML.htm#Section_15.2.4>` doesn't inherit from anything, it's the only *built-in object *that is described to have `null` as the value of its [[Prototype]] internal property. Regards, -- Christian C. Salvadó @cmsalvado <http://twitter.com/cmsalvado> -- 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]
