自丢网

标题: ES6中super还可以调用父类方法案例教程 [打印本页]

作者: admin    时间: 2020-3-21 11:39
标题: ES6中super还可以调用父类方法案例教程
ES6中super还可以调用父类方法案例教程
代码如下:
  1.     <script>
  2.         class Father {
  3.             constructor(x, y) {
  4.                 this.x = x;
  5.                 this.y = y;
  6.             }
  7.             sum() {
  8.                 console.log(this.x + this.y);
  9.             }
  10.         }
  11.         class Son extends Father {
  12.             som() {
  13.                 super.sum();
  14.             }
  15.         }
  16.         son = new Son(5, 8);
  17.         son.som();
  18.     </script>
复制代码
输出结果为:13





欢迎光临 自丢网 (https://www.zidiu.com/) Powered by Discuz! X3.5