加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – React,为什么在ES6类构造函数中使用super(props)?

发布时间:2020-12-15 20:55:06 所属栏目:百科 来源:网络整理
导读:参见英文答案 What’s the difference between “super()” and “super(props)” in React when using es6 classes?6个 我意识到super关键字可用于调用父组件中的函数.但是,我不完全清楚为什么你会在下面的例子中使用super关键字 – 只是传递它传递给构造函
参见英文答案 > What’s the difference between “super()” and “super(props)” in React when using es6 classes?6个
我意识到super关键字可用于调用父组件中的函数.但是,我不完全清楚为什么你会在下面的例子中使用super关键字 – 只是传递它传递给构造函数的任何道具.

有人可以了解在ES6类构造函数中使用super关键字的各种原因吗?

constructor(props) {
    super(props);

    this.state = {
      course: Object.assign({},this.props.course),errors: {   }
    };

    this.updateCourseState = this.updateCourseState.bind(this);
  }
super允许您访问父类的构造方法.包含props的唯一原因是在构造函数中访问this.props.

What’s the difference between “super()” and “super(props)” in React when using es6 classes?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读