Every object in Javascript has a prototype. Try it:
var Richard = new Object();
alert(typeof(Richard.prototype));
The result is depressing, the browser pops up undefined...
What is going on?
Look at another example:
function Richard(){}
alert(typeof(Richard.prototype));
The above example seems to show that only function objects have prototypes, while general Object objects do not have prototypes. What are the facts?
We will understand if we execute another sentence:
var Richard = new Object();
alert(Richard.__proto__);
Do you understand?
In fact, we all have a misunderstanding, that is, the prototype that forms the prototype chain of a Javascript object is a property named prototype, and it is accessible. In fact, Javascript's prototype and the property named prototype have nothing to do with each other at the beginning. They are two different things.
For general objects, we can only access the prototype inherited from the Object object through attributes such as __proto__;
For function objects, when they are created, they have been The prototype of the Function object is assigned to the prototype attribute.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn