First, Concept introduction
Prototype Object :
The prototype object. In JavaScript, each object inherits another object, which is called a prototype object. Except for null , it does not have its own prototype object.
All properties and methods on the prototype object can be shared by the derived object. A prototype object is automatically assigned through the instance object of the constructor instance. Each one
The prototype property of the constructor is the prototype object of the instance object.
Ii. Use of prototypes
For example, an attribute color is added to the source object of animal, and the result is shared by the instance object Bear1, Bear2. If you change the color value, it is reflected on each instance object.
Three, the problem of the prototype solution
If you do not use prototypes, let's look at the following uses. Animal object has the say method, to different instances out of the object, this method provides the same function, but made a trip Bear1.say = = = Bear2.say comparison, return false.
The description does not pass the property, method, which is based on the prototype object, that is, the function can be internally customized properties, methods, all instantiated objects will generate these two objects, and can not be shared, a little waste of system resources.
[Front-end JS Learning notes] JavaScript prototype objects