参考:http://www.phonegap100.com/thread-4911-1-1.htmlhtml
Es6中的super能够用在类的继承中,super关键字,它指代父类的实例(即父类的this对象)。子类必须在constructor方法中调用super方法,不然新建实例时会报错。这是由于子类没有本身的this对象,而是继承父类的this对象,而后对其进行加工。若是不调用super方法,子类就得不到this对象。函数
class Person { constructor (name) { this.name = name; } } class Student extends Person { constructor (name, age) { super(); // 用在构造函数中,必须在使用this以前调用 this.age = age; } }
为何官方的列子里面写个super(props):学习
只有一个理由须要传递props做为super()的参数,那就是你须要在构造函数内使用this.propsthis
那官方提供学习的例子中都是写成super(props),因此说写成super(props)是彻底没问题的,也建议就直接这样写。spa