<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>
js的组合继承
原文地址:https://www.cnblogs.com/zhumeiming/p/9678664.html