AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
# 组合式继承 ***** **原型链继承 + 借用构造函数继承** ```javascript //组合式继承: 原型链继承(不能访问属性) + call继承(不能访问方法) // 构造函数 function Person(name,age){ this.name = name; this.age = age; } // 添加方法在原型上 Person.prototype.eat = function(){ console.log("吃饭"); } // 学生类 function Student(name,age,score){ Person.call(this,name,age);//call继承 this.score = score; } //原型链继承 Student.prototype = new Person(); // 添加方法 Student.prototype.say = function(){ console.log("世界,你好"); } // 实例化对象 var stu1 = new Student("小明",18,100); console.log(stu1.name,stu1.age,stu1.score); stu1.eat(); //可以访问方法 stu1.say(); ```