javascript原型链

-

每个对象都有__proto__属性(访问器属性),这个属性可以访问到对象的原型对象(prototype);

拿构造函数的实例对象来举例,看看原型链的指向

function Person(name,age){
    this.name = name;
    this.age = age;
}

let person1 = new Person("张三",18);

console.log(person1.__proto__ === Person.prototype);//true
console.log(Person.prototype.__proto__ === Object.prototype);//true
console.log(Object.prototype.__proto__);//null

由此可以看出,原型链的指向关系

p.__proto__ 指向 Person.prototype

Person.prototype.__proto__ 指向 Object.prototype

Object.prototype.__proto__ 指向 null

-