自丢网
标题:
ES6中super还可以调用父类方法案例教程
[打印本页]
作者:
admin
时间:
2020-3-21 11:39
标题:
ES6中super还可以调用父类方法案例教程
ES6中super还可以调用父类方法案例教程
代码如下:
<script>
class Father {
constructor(x, y) {
this.x = x;
this.y = y;
}
sum() {
console.log(this.x + this.y);
}
}
class Son extends Father {
som() {
super.sum();
}
}
son = new Son(5, 8);
son.som();
</script>
复制代码
输出结果为:13
欢迎光临 自丢网 (https://www.zidiu.com/)
Powered by Discuz! X3.5