function Parent(name) {
this.name = name;
}
Parent.prototype.sayName = function() {
console.log(this.name);
}
function Child(name, age) {
Parent.call(this, name); // 继承属性
this.age = age;
}
Child.prototype = Object.create(Parent.prototype); // 通过寄生式继承继承方法
Child.prototype.constructor = Child; // 修正构造函数指向
Child.prototype.sayAge = function() {
console.log(this.age);
}
let child = new Child('Kevin', 25);
child.sayName(); // Kevin
child.sayAge(); // 25