- <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>
来源: http://www.bubuko.com/infodetail-2774447.html