- 在子类的构造函数中通过call借助父类的构造函数
- 将子类的原型对象修改为父类的实例对象
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.say = function () {
console.log('Hi');
}
let per = new Person();
function Student(name, age, score) {
Person.call(this, name, age);
this.score = score;
this.stud = function () {
console.log('我是小学生');
}
}
Student.prototype = new Person();
Student.prototype.constructor = Student;
Student.prototype.play = function () {
console.log('我喜欢唱跳rap篮球');
}
let stu = new Student('踩墟捆', 12, 59);
console.log(stu.name, stu.age, stu.score);
stu.say();
stu.play();
per.paly();