<script>
//继承的时候,不用改变原型的指向,直接调用父级的构造函数拿来
// 作为属性赋值就可以了。
//借用构造函数:构造函数名字.call(当前对象,属性,属性,属性.....)
//解决了属性继承,并且值不重复的问题
//缺陷:父级类别中的方法并不能够继承
function Person(name,age,sex,weight) {
this.age= age;
this.name=name;
this.sex=sex;
this.weight=weight;
}
Person.prototype.SayHi = function () {
console.log("您好啊!");
};
function Student(name,age,sex,weight,source) {
//借用构造函数
Person.call(this,name,age,sex,weight);
this.source=source;
}
var stu = new Student("小明",10,"10kg","100");
console.log(stu.name,stu,stu.sex,stu.age,stu.weight);
</script>
//继承的时候,不用改变原型的指向,直接调用父级的构造函数拿来
// 作为属性赋值就可以了。
//借用构造函数:构造函数名字.call(当前对象,属性,属性,属性.....)
//解决了属性继承,并且值不重复的问题
//缺陷:父级类别中的方法并不能够继承
function Person(name,age,sex,weight) {
this.age= age;
this.name=name;
this.sex=sex;
this.weight=weight;
}
Person.prototype.SayHi = function () {
console.log("您好啊!");
};
function Student(name,age,sex,weight,source) {
//借用构造函数
Person.call(this,name,age,sex,weight);
this.source=source;
}
var stu = new Student("小明",10,"10kg","100");
console.log(stu.name,stu,stu.sex,stu.age,stu.weight);
</script>