* 原型实现继承 * 借用构造函数实现继承 * 组合继承:原型继承+借用构造函数继承 * */ function Person(name,age,sex) { this.name=name; this.age=age; this.sex=sex; } Person.prototype.sayHi=function () { console.log("你好啊,嘻嘻嘻"); }; function Studeny(name,age,sex,score) { //借用构造函数:属性值重复的问题 Person.call(this,name,age,sex,score); this.score=score; } //改变原型指向====》继承 Studeny.prototype=new Person();//不传值 Studeny.prototype.eat=function () { console.log("吃好吃的"); }; var stu1=new Studeny("小美",20,"女","100"); console.log(stu1.name,stu1.age,stu1.sex,stu1.score); stu1.sayHi(); stu1.eat(); var stu2=new Studeny("小丽",22,"女","120"); console.log(stu2.name,stu2.age,stu2.sex,stu2.score); stu1.sayHi(); stu1.eat();