企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
## 原型继承 继承:是类型和类型之间的关系. 继承目的:把子类型中共同的成员提取到父类型中,代码重用. ``` function Person(){ this.name = 'jack'; this.age; this.gender; } function Student(){ this.score = 100; } Student.prototype = new Person(); //原型继承,这里只继承了一次,多次调用很不方便 Student.prototype.constructor = Student; //必须指定构造函数 var s1 = new Student(); //原型继承无法设置构造函数的参数 console.log(s1.constructor); function Teacher(){ this.salary = 3000; } ```