JS中子类的实例属性为什么可以访问父类的实例属性?
check
check 2017-03-03 10:54:12
0
2
713
class Person {
  constructor(name, age) {    this.name = name    this.age = age
  }
  
  test() { }
}class Student extends Person {
  constructor(name, age, no) {    super(name, age)    this.no = no
  } 
  say() {    console.log(`name: ${this.name}, age: ${this.age}, no: ${this.no}`)
  }
}let student = new Student('mrcode', 21, '11403080435')
student.say()

student可以访问test方法,这点可以理解。 但是为什么通过Student中的this可以访问到父类中的name, age呢? ES6中的class只是原型链的语法糖。 原型链上的对象都是原型。 哪里来的name, age属性呢?

check
check

热门教程
더>
最新下载
더>
网站特效
网站源码
网站素材
프론트엔드 템플릿
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!