react super() and super(props)

subclass: subclass is a class that extends another class. 即子類。ide

 

In ES2015, to use 'this' in subclasses, we first must call super().this

Why 'this' can not be allowed before super()?spa

Because 'this' is uninitialized if super() is not called.get

ES6 class constructors must call super() if they are subclasses. However, a subclasses does not have to have a constructor().it

 

What super() does?class

super() will call the constructor of its parent's class. (super() refers to the parent)call

 

The difference between super() and super(props)
di

Call super(props) only if you want to access 'this.props' inside the constructor.ant

When you use super() inside the constructor, you can use 'props' to get props.sse

相關文章
相關標籤/搜索