/*
原型及原型链:
1. 所有的函数都有一个prototype的属性(指针),该属性指向了这个函数的原型对象。
2. 所有的对象都有一个__proto__的属性(指针),该属性指向了这个对象的原型对象。
每一个原型对象也都有一个__proto__的属性,指向它的父级原型对象,最终指向null对象(原型链)
3. 第一个原型对象都有一个constructor的属性,该属性指向这个原型对象的构造函数。
*/
function Father(){}
Father.prototype.name = ‘张三’;
Father.prototype.age = 88;
Father.prototype.showName = function(){
return this.name;
}
Father.prototype.showAge = function(){
return this.age;
}
function Son(){}
Son.prototype = new Father();
let father = new Father();
let son = new Son();
Son.prototype.name = ‘张小三’;
console.log(father.showName());
console.log(son.showName(),son.showAge());
//原型链继承