Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the principle of JavaScript object prototype chain?

Shulou Source: shulou.com Published: 2022-06-03 08:03:58 10月30日 Update

Today, I will talk to you about the principle of JavaScript object prototype chain, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

A js object, in addition to its own properties, automatically generates proto, class, and extensible properties, where the proto property points to the prototype of the object.

Object properties also have configuration methods for writable, enumerable, configurable, value, and get/set.

There are three ways to create objects:

First, use literal quantity to create directly.

Second, it is based on the prototype chain.

To analyze the above figure, the main points are as follows:

1. You can create a new object with the new operator, and foo is a custom function, that is, the object.

two。 You can set properties on the foo.prototype.

3. The variable z is on the prototype chain and is a property of foo.prototype, not a property of obj.

4. The prototype chain is obj- > foo.prototype- > Object.prototype- > null.

To analyze the above figure, the main points are as follows:

1. If you define a variable with the same name as on the prototype chain, it does not overwrite the variable on the prototype chain, but adds a copy to the object itself.

The 2.delete operator does not affect the variables already on the prototype chain, but only removes the attributes of the object itself.

Third, use Object.create to create.

To analyze the above figure, the main points are as follows:

The 1.Object.create generates a new object based on the passed parameters, and the input parameter becomes part of its prototype chain.

The object created by 2.Object.create (null) points directly to null.

After reading the above, do you have any further understanding of the principle of JavaScript object prototype chain? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Objects prototypes properties variables above content essentials analysis principle pointing operators operations functions copies parameters literals methods methods are in more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft OPPO Reno Linux Docker Shulou Tech Info