SOURCE

// 三层结构理解原型链
// 1. 最底层:Object 构造函数(JS 内置)
// Object.prototype 是所有对象的“根原型”,其 __proto__ 为 null(原型链终点)
console.log(Object.prototype.__proto__); // null

// 2. 中间层:Person 构造函数(自定义)
function Person(name) {
  this.name = name;
}
// Person.prototype 的 __proto__ 指向 Object.prototype(继承自 Object)
console.log(Person.prototype.__proto__ === Object.prototype); // true

// 3. 最上层:实例 mike
const mike = new Person('Mike');
// mike 的 __proto__ 指向 Person.prototype
console.log(mike.__proto__ === Person.prototype); // true

// 原型链完整路径:
// mike → Person.prototype → Object.prototype → null

// 内容分割 /////////////////////////////////////

// 验证原型链关系
console.log(mike.__proto__ === Person.prototype); // true
console.log(Person.prototype.constructor === Person); // true

// 验证 mike 自身没有 constructor 属性
console.log(mike.hasOwnProperty('constructor')); // false

// 验证 mike.constructor 实际来自原型链
console.log(mike.constructor === mike.__proto__.constructor); // true
console.log(mike.constructor === Person.prototype.constructor); // true

// 内容分割 /////////////////////////////////////

// 获取 mike 的原型对象
const prototypeOfMike = Object.getPrototypeOf(mike);

// 验证与 Person.prototype 相同
console.log(prototypeOfMike === Person.prototype); // true

// 验证与 __proto__ 等效
console.log(prototypeOfMike === mike.__proto__); // true
console 命令行工具 X clear

                    
>
console