JavaScript----prototypes, prototype chains (what are prototypes)

Source: Internet
Author: User

Like "closures", the concept of "prototypes" is often mentioned.

In fact, this "concept" should be with the constructor, the object is put together, but because of the time relationship, the first part of the extraction. When we talk about this concept, we'll start with an overview of the "objects" in JavaScript.

What is an object?

The explanation given in the JavaScript authoritative guide is that an object is a composite data type that centralizes multiple data values in a single cell and allows names to be used to access those values. Or an unordered collection of attributes, each with its own name and value.

What is a prototype?

We create an empty object var a = new Objecg (), and then new sets the prototype of the object. The prototype of an object is the value of the prototype property of its constructor. All functions have a prototype property, and when the function is defined, the prototype property is automatically created and initialized. "_proto_" is generally used to denote

What is a prototype chain?

In interpreting this noun, we want to know that all objects in JavaScript inherit from the object class. Personally, this concept is more difficult to describe clearly in the language. Here I use a graph to indicate:

As explained below, Class B inherits Class A, and when we look for a property "F" in the B constructor, if none is in B, then the program looks up the properties of class "A", if it has not been looked up until it finds an object. This process forms the prototype chain. The more simple and brutal diagram is as follows:

This is the prototype chain.

Definition: Keep looking up through your own prototype until the upward prototype is empty (object). This chain is the prototype chain.

JavaScript----prototypes, prototype chains (what are prototypes)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.