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)