react super() and super(props)

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

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

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

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

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

What super() does?

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

The difference between super() and super(props)

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

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

上一篇:CustomEvent自定义事件


下一篇:ArcGIS属性选择器筛选