1: What is a constructor?

To understand what a constructor is, you need to understand the difference between a normal function and a constructor.

// A normal function
var Parent = function() {};// Parent is a constructor, and p1 is its instance
var p1 = new Parent();
Copy the code

2: What is unique

protoThe constructor attribute is unique to the object

The Prototype attribute is unique to the function

Functions are also objects, so functions also have attributes __proto__ and constructor

3: Prototype attribute

We can use prototype to add attributes to a function, and all instantiated objects of this function can inherit the attributes we added through it.

Usage:

Function name. Prototype instead of object name

4: Pointing relationship between constructor and prototype object

Constructor = p1; constructor = p1constructorMethod, fromp1I got it from the prototype.Copy the code

5:proto(Find the prototype)

Understand examples of prototypes