目录
1、基础示例
- 1、基础示例
- 2、笔试题——1
Professor.prototype.tSkill = 'JavaScript'; function Professor() {} var professor = new Professor(); Teacher.prototype = professor; function Teacher() { this.mSkill = 'html'; } var teacher = new Teacher(); Student.prototype = teacher; function Student() { this.pSkill = 'css'; } var student = new Student(); console.log(student); // Student {pSkill: 'css'} console.log(student.tSkill); // JavaScript console.log(student.mSkill); // html console.log(student.pSkill); // css
原型链的顶端是Object.prototype Object.prototype下保存了toString()
2、笔试题——1Professor.prototype.tSkill = 'JavaScript'; function Professor() {} var professor = new Professor(); Teacher.prototype = professor; function Teacher() { this.mSkill = 'html'; this.success = { alibaba: '28', tencent: '30' }; } var teacher = new Teacher(); Student.prototype = teacher; function Student() { this.pSkill = 'css'; } var student = new Student(); student.success.baidu = '100'; student.success.alibaba = '29'; console.log(teacher); // Professor {mSkill: 'html', success: {… }} // mSkill: "html" // success: {alibaba: '29', tencent: '30', baidu: '100'} // [[Prototype]]: Professor console.log(student); // Student {pSkill: 'css'}