prototype
The prototype property of each function is called prototype (prototype object)
effect:
- Store properties and methods (can be shared)
- Inheritance
Every object has a _proto_ attribute, which points to its prototype
const arr = new Array(1, 2, 3, 4, 5)
arr.reverse()
arr.sort()
console.log(arr._proto_ === Array.prototype) // true
prototype chain
Each object has a _proto_ attribute, which points to its prototype object, and the prototype object also has a _proto_ attribute, which points to the prototype object of the prototype object. The chain structure formed layer by layer is called the prototype chain
person对象 -> Person.prototype->Object.prototype->null