concept

1. All functions and objects have the __proto__ attribute

2. Only functions have the property prototype, called the prototype object

3. __proto__ refers to his father’s prototype [important]

Var A = new Function() var A = new A() a.__proto__ === a.prototype === undefined // 2 __proto__ === Object. Prototype == 3, a.prototye is an Object, __proto__ === null // the parent is Object a. __proto__ === Function. Prototype // the parent is Function object.prototype. Object.__proto__ === Function. Prototype Function.__proto__ === Object. Prototype // 3 function.__proto__ === FunctionCopy the code

Take a look at the code

Object.prototype.name = 'new Array' var a = new Array() console.log(a.nameCopy the code

Why does a.name === ‘xiao fang’

  1. Look for the name attribute on A itself, not 2
  2. Name = a.__proto__ (array. prototype), not 3
  3. Prototype = a.__proto__.__proto__(Object. Prototype) name = a.__proto__

The prototype chain I understand is a route through __proto__ and prototype, where __proto__ is the line and Prototype is the node

var Person = new Function()
var person = new Person()
Copy the code