天天看點

es6-class 類繼承(子類對父類的重寫)

//  static 标注的屬于類不屬于執行個體
    class Phone {
      constructor(name, price) {
        this.name = name;
        this.price = price
      }
      stop(){
        console.log('執行暫停')
      }
    }
    class amartPhone extends Phone {
      constructor(name, price,color,size) {
        super(name, price);
        this.name = name;
        this.price = price
        this.color = color
        this.size = size
      }   
      play(){
        console.log('執行播放')
      }
      stop(){
        console.log('執行暫停222')
      }
    }
    const amar = new amartPhone('小木', '240','黑色','50*100')
    console.log(amar);
    amar.stop()
    amar.play()