您当前的位置: 首页 >  Java

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JavaScript之原型链

发布时间:2022-02-16 10:55:14 ,浏览量:0

目录
  • 1、基础示例
  • 2、笔试题——1
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'} 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.3784s