Each object in JavaScript has a prototype. Try this:
Copy Code code as follows:
var Richard = new Object ();
Alert (typeof (Richard.prototype));
The result is depressing, the browser bounce out is undefined ...
What the hell is going on here?
Look at one more example:
Copy Code code as follows:
function Richard () {}
Alert (typeof (Richard.prototype));
The above example seems to show that only the function object has prototype, and the general object is not prototype, what is the truth?
One more thing, we'll see:
Copy Code code as follows:
var Richard = new Object ();
alert (richard.__proto__);
Are you clear?
In fact, we all have a misunderstanding, is that the formation of Javascript objects prototype chain prototype is a name prototype attributes, and is accessible. In fact, the prototype of Javascript and the attribute named prototype at the beginning have nothing to do with, it is two different things.
For ordinary objects, we can only access the prototype inherited from object objects by __proto__ such attributes;
For a function object, when it is established, the prototype of the function object has been assigned to the prototype property.