Skip to content
登录后刷题更便捷

寄生式组合继承的实现?

难度:
js
function Person(name) {
  this.name = name;
}

Person.prototype.sayName = function () {
  console.log("My name is " + this.name + ".");
};

function Student(name, grade) {
  Person.call(this, name);
  this.grade = grade;
}

Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;

Student.prototype.sayMyGrade = function () {
  console.log("My grade is " + this.grade + ".");
};

内容仅供参考,难免有不恰当的地方,如果有问题欢迎及时反馈
部分内容来自网络,如果不慎侵犯您的权益,请联系我们,以便及时删除侵权内容