借用构造函数

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 Student(name,age,sex,weight,score) {
//借用构造函数
    Person.call(this,name,age,sex,weight);
    this.score = score;
}

var stu1 = new Student("小明",20,"男","10kg","100");
console.log(stu1.name,stu1.age,stu1.sex,stu1.weight,stu1.score);

var stu2 = new Student("小画",30,"女","20kg","120");
console.log(stu2.name,stu2.age,stu2.sex,stu2.weight,stu2.score);

你可能感兴趣的:(借用构造函数)