【发布时间】:2016-10-19 20:40:45
【问题描述】:
我意识到 super 关键字可以用来调用父组件中的函数。但是,我不完全清楚为什么要在下面的示例中使用 super 关键字 - 只需将传递给构造函数的任何道具传递给它。
有人能解释一下在 ES6 类构造函数中使用 super 关键字的各种原因吗?
constructor(props) {
super(props);
this.state = {
course: Object.assign({}, this.props.course),
errors: { }
};
this.updateCourseState = this.updateCourseState.bind(this);
}
【问题讨论】:
-
查看类声明会很有帮助。例如
class SpecialDialog extends Dialog {
标签: reactjs ecmascript-6 super