A little front-end knowledge every day 07 - prototype, prototype chain

prototype

The prototype property of each function is called prototype (prototype object)

effect:

  1. Store properties and methods (can be shared)
  2. Inheritance
    insert image description here
    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

Guess you like

Origin blog.csdn.net/qq_33591873/article/details/128239893