class继承

121 阅读1分钟
<script>
    class Point {
       constructor(x, y) {
          this.x = x
          this.y = y
       }
       say() {
          console.log("我父类方法");
       }
    }
    class ColorPoint extends Point {
       //子类继承父类,必须实现构造函数
       constructor(x,y,z){
          super(x,y)
          this.z = z  
       }
       hi(){
          super.say()//调用父类方法
       }
    }
    const p = new ColorPoint(10,20)
    p.hi()
    // console.log(p.x);
</script>