参考:http://www.phonegap100.com/thread-4911-1-1.html

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.props

那官方提供学习的例子中都是写成super(props),所以说写成super(props)是完全没问题的,也建议就直接这样写。

最新文章

  1. 【翻译】MongoDB指南/CRUD操作(一)
  2. POJ3666Making the Grade[DP 离散化 LIS相关]
  3. Vue 为什么在 HTML 中监听事件?
  4. HDU 5694---BD String
  5. [POJ3177]Redundant Paths(双连通图,割边,桥,重边)
  6. Redisql: the lightning fast data polyglot【翻译】 - Linvo's blog - 博客频道 - CSDN.NET
  7. Grunt使用教程(限winows)
  8. leetcode水题(一)
  9. J2EE规范标准
  10. ViewModel学习
  11. DS图遍历--广度优先搜索
  12. 解析Javascript事件冒泡机制(转) 本文转自:http://blog.csdn.net/luanlouis/article/details/23927347
  13. Lua入门教程
  14. 善用Eclipse的代码模板功能
  15. java 异常链
  16. 前端html页面学习---html部分
  17. Android实战——GreenDao3.2的使用,爱不释手
  18. Harbor快速部署到Kubernetes集群及登录问题解决
  19. hdu 5943(素数间隔+二分图匹配)
  20. 用Python实现BP神经网络(附代码)

热门文章

  1. Spring中都用到了哪些设计模式
  2. size_t为什么重要
  3. XCODE真机调试No Devices Registered
  4. HashMap测试程序1
  5. mysql版本
  6. Trailing Zeroes (III) -;lightoj 1138
  7. 去掉注释index.html
  8. Getting Started Tutorial from msdn
  9. ORACLE Physical Standby DG搭建
  10. DB-MD:MD/主数据