super关键字用于访问和调用对象父类上的函数。可以调用父类的构造函数,也可以调用父类的普通函数。
- <script>
- class Father {
- constructor(x, y) {
- this.x = x;
- this.y = y;
- }
- sum() {
- console.log(this.x + this.y);
- }
- }
- class Son extends Father {
- constructor(x, y) {
- super(x, y);
- }
- }
- son = new Son(5, 8);
- son.sum();
- </script>
复制代码
|
|