原型链 - ChatGPT
原型(Prototype)
构造函数与原型
function Person(name) {
this.name = name;
}
Person.prototype.sayHello = function () {
console.log("Hello, my name is " + this.name);
};
const p1 = new Person("Alice");
p1.sayHello(); // Hello, my name is Alice
console.log(p1.__proto__ === Person.prototype); // true
console.log(Person.prototype.__proto__ === Object.prototype); // true原型链
原型链的终点
原型链继承
ES6 Class 继承原型链
总结
Last updated