- prototype
- proto
- constructor
Each function has a prototype property that contains a constructor and proto object. Each object has a proto that points to its constructor’s prototype. Prototype is called explicit and proto is implicit. Prototype provides the ability to provide properties and methods to prototype objects. We can add methods to prototype objects through Prototype, but it is best not to modify the methods of existing native objects, such as array, object built-in methods, so as not to cause prototype contamination
The function Person (name) {enclosing name = name | | 'John'} var Person = new Person () the console. The log (Person. Name) / / 'John' var Person2 = new Person(' Yang ') console.log(person2.name)Copy the code
When an object is built from a prototype, we look at the object itself first, if not, on its implicit prototype (the constructor’s explicit prototype), otherwise on the constructor’s prototype proto, and keep looking up until we find it. If not, return undefined, which forms a chain structure