ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] # 原型链继承 <br> ```javascript //定义个人类 functionPerson(name, age){ this.name\=name; this.age\=age; } //方法放在原型上 Person.prototype.say\=function(){ console.log("世界,你好"); }; // 定义个学生类 functionStudent(score){ this.score\=score; this.eat\=function(){ console.log("我是Student上的方法"); } } // 原型链继承 Student.prototype \=newPerson("wc",13);//Student的this指向变成了Person //把方法写在原型上,要在继承之后写 Student.prototype.like\=function(){//在原型链上添加的方法要在原型链继承之后写 console.log("吃饭,睡觉"); } // 实例化对象 var per \=newStudent(100); console.log(per.name, per.age, per.score);     per.say();     per.eat(); ``` <br> ***** ## 缺陷 **不能获取构造函数上的私有属性,只能获取改构造函数原型上的方法**