企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组合式继承 ***** **原型链继承 + 借用构造函数继承** ```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(); ```