JavaScript之原型链
Posted web半晨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript之原型链相关的知识,希望对你有一定的参考价值。
目录
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、笔试题——1
Professor.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'
以上是关于JavaScript之原型链的主要内容,如果未能解决你的问题,请参考以下文章