js的组合继承
<script>
//组合继承:原型链继承+借用构造函数
function Person(name,age){
this.name=name;
this.age=age;
}
Person.prototype.setName=function (name){
this.name=name;
}
function Student(name,age,price){
Person.call(this,name,age); //相当于调用this.Person(name,age),等价于this.name=name;this.age=age;
this.price=price;
}
Student.prototype=new Person();
Student.prototype.constructor=Student;
Student.prototype.setPrice=function (price){
this.price=price;
}
var s=new Student('zain',26,20000);
console.log(s.name,s.age,s.price);
</script>
sometimes the hardest part isn't letting go,but rather start over

浙公网安备 33010602011771号