自丢网
标题:
ES6调用父类函数super关键字使用方法教程
[打印本页]
作者:
admin
时间:
2020-3-21 11:26
标题:
ES6调用父类函数super关键字使用方法教程
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>
复制代码
欢迎光临 自丢网 (https://www.zidiu.com/)
Powered by Discuz! X3.5