mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 03:02:21 +00:00
docs(class-extends): fix super() #657
This commit is contained in:
parent
31bef7b0bc
commit
25cc21754d
@ -29,7 +29,7 @@ class ColorPoint extends Point {
|
|||||||
|
|
||||||
上面代码中,`constructor`方法和`toString`方法之中,都出现了`super`关键字,它在这里表示父类的构造函数,用来新建父类的`this`对象。
|
上面代码中,`constructor`方法和`toString`方法之中,都出现了`super`关键字,它在这里表示父类的构造函数,用来新建父类的`this`对象。
|
||||||
|
|
||||||
子类必须在`constructor`方法中调用`super`方法,否则新建实例时会报错。这是因为子类没有自己的`this`对象,而是继承父类的`this`对象,然后对其进行加工。如果不调用`super`方法,子类就得不到`this`对象。
|
子类必须在`constructor`方法中调用`super`方法,否则新建实例时会报错。这是因为子类自己的`this`对象,必须先通过父类的构造函数完成塑造,得到与父类同样的实例属性和方法,然后再对其进行加工,加上子类自己的实例属性和方法。如果不调用`super`方法,子类就得不到`this`对象。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
class Point { /* ... */ }
|
class Point { /* ... */ }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user