借用构造函数

* 借用构造函数:构造函数的名字.call(当前对象,属性,属性,属性,····)
* 解决了属性继承,并且值不重复的问题
* 缺陷:父级类别中的方法不能继承
* */
function Person(name,age,sex,weight) {
this.name=name;
this.age=age;
this.sex=sex;
this.weight=weight;
}
Person.prototype.sayHi=function () {
console.log("你好啊");
};
function Studeny(name,age,sex,weight,score) {
//借用构造函数
Person.call(this,name,age,sex,weight,score);
this.score=score;
}
var stu1=new Studeny("小米",8,"男","10g","100");
console.log(stu1.name,stu1.age,stu1.sex,stu1.weight,stu1.score);
var stu2=new Studeny("小明",9,"女","10g","110");
console.log(stu2.name,stu2.age,stu2.sex,stu2.weight,stu2.score);
var stu3=new Studeny("小红",10,"妖","10g","120");
console.log(stu3.name,stu3.age,stu3.sex,stu3.weight,stu3.score);
原文地址:https://www.cnblogs.com/lujieting/p/10067321.html