constructor中super与props参数一起使用的目的是什么?
What is the purpose of using super with props in the constructor?
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: medium
分类: JavaScript in React
标签: constructor, super, props, this.props, ES6
参考答案摘要
核心答案 在调用方法之前,子类构造函数无法使用 this 引用 super() 。 在 ES6 中,在子类的 constructor 中必须先调用 super 才能引用 this 。 在 constructor 中可以使用 this.props (需要 super(props) )。 使用props class MyComponent extends React.Component { const...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。