【问题标题】:ReactJS: what is super() for in this case? [duplicate]ReactJS:在这种情况下 super() 是什么? [复制]
【发布时间】:2017-02-15 19:46:36
【问题描述】:

我正在学习 ReactJS。我认为现在创建组件的最佳方法是扩展类 React.Component。我的问题是,这个super(props)到底在做什么?

我以为可能是设置了基本的props对象,但是如果我删除整个构造方法,它仍然有效。

【问题讨论】:

标签: javascript function class reactjs constructor


【解决方案1】:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super

Super 调用父类的构造函数,它在从另一个类“扩展”的类的构造函数中是必需的。

【讨论】:

  • 这个问题与 React 行为有关,而不是一般super
猜你喜欢
  • 1970-01-01
  • 2017-03-05
  • 2013-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多