标签:name price 原型 tor new 等价 student console javascrip
<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>
标签:name price 原型 tor new 等价 student console javascrip
原文地址:https://www.cnblogs.com/zhumeiming/p/9678664.html