super(props) 的作用是什么?
What is the purpose of super(props)?
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: easy
分类: Frontend
标签: super, props
参考答案摘要
答案 子类的构造函数在调用 super() 之前无法使用 this。同时,如果它们是子类,ES2015 的 class 构造函数必须调用 super()。把 props 传给 super() 的原因,是为了让你能在 constructor 中访问 this.props。
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。