0

What is the scope of the method super() in react.js

15th Nov 2020, 11:06 AM
Andrei I
Andrei I - avatar
3 odpowiedzi
+ 6
super keyword is not a React specific method but ES6+ keyword. It's recommended to have a good understanding of modern JavaScript features (ES6+) before leaping into React. We need super keyword when inheritance is present. See this(entire lesson): https://www.sololearn.com/learn/JavaScript/2979/ "The super keyword is used to access and call functions on an object's parent. ... When used in a constructor, the super keyword appears alone and must be used before the this keyword is used. The super keyword can also be used to call functions on a parent object." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super So, yes, when extending React.Component you should call super() in the constructor before using "this" keyword.
15th Nov 2020, 11:36 PM
Kevin ★
0
React.component
15th Nov 2020, 12:51 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
I didn't mean react scope. I ment its porpoise . What is it used for
15th Nov 2020, 2:23 PM
Andrei I
Andrei I - avatar