Home > Web Front-end > JS Tutorial > About prototype_javascript skills of Javascript objects

About prototype_javascript skills of Javascript objects

WBOY
Release: 2016-05-16 16:49:02
Original
1060 people have browsed it

Every object in Javascript has a prototype. Try it:

Copy code The code is as follows:

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:
Copy the code The code is as follows:

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:
Copy the code The code is as follows:

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template