企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 借用构造函数继承(call继承,经典继承) <br> >[danger]构造函数.call(当前对象,参数,参数..) **** window.构造函数.call(当前对象,参数,参数..) window可以省略 ***** **只能获取属性,不能获取方法** ```javascript // 构造函数 Person functionPerson(name,age){ this.name=name; this.age=age; this.eat=function(){ console.log("吃饭"); } }; // 方法挂原型上 Person.prototype.say=function(){ console.log("世界,你好"); } // 构造函数Student functionStudent(name,age,score){ Person.call(this,name,age); //call继承,继承Person方法中的属性,在这里省略了window不写   window.Person.call(this) this.score=score; } // 实例化对象 var stu1 =newStudent("小明",3,100); console.log(stu1); console.log(stu1.name); stu1.eat();//可以拿到Person上的方法 stu1.say();//call  拿不到Person原型上的方法 ``` <br> ## 缺陷 **借用构造函数没有办法拿到借用函数原型上的方法,只能获取借用构造函数上的私有属性** **使用混合式继承解决**