<script>
//组合继承的优点在于属性跟方法都可以继承
//组合继承=原型继承+构造函数继承
function Person(name,age,sex) {
this.age=age;
this.sex=sex;
this.name = name;
}
Person.prototype.SayHi=function () {
console.log("您好啊!");
};
function Student(name,age,sex,score) {
//借用构造函数来解决属性值重复的问题
Person.call(this,name,age,sex);
this.score=score;
}
Student.prototype=new Person();//不传值
Student.prototype.eat=function () {
console.log("吃大西瓜");
};
var stu = new Student("小明",10,"男","100分");
console.log(stu.name,stu.sex,stu.age,stu.score);
stu.eat();
stu.SayHi();
</script>
//组合继承的优点在于属性跟方法都可以继承
//组合继承=原型继承+构造函数继承
function Person(name,age,sex) {
this.age=age;
this.sex=sex;
this.name = name;
}
Person.prototype.SayHi=function () {
console.log("您好啊!");
};
function Student(name,age,sex,score) {
//借用构造函数来解决属性值重复的问题
Person.call(this,name,age,sex);
this.score=score;
}
Student.prototype=new Person();//不传值
Student.prototype.eat=function () {
console.log("吃大西瓜");
};
var stu = new Student("小明",10,"男","100分");
console.log(stu.name,stu.sex,stu.age,stu.score);
stu.eat();
stu.SayHi();
</script>