1. 程式人生 > >es6類聲明,class總結

es6類聲明,class總結

turn script super div 無需 ext 聲明 class a class

1、class的基本寫法

class a{
  // 傳入參數或者寫入固定參數
  constructor(a,b){
    this.a=a
    this.b=b
  }
  // 可直接調用的計算後的參數
  get c(){
    return this.a+this.b
  }
  // 可以調用的普通的方法
  calc(){
    return this.a*this.b
  }
  // 無需new就可以直接引用的方法
  static mius(d,e){
    return d-e
  }
}
var x=new a()

2、繼承class

class l extends a {
  calc(){
    console.log(super.calc())
    return this.a-this.b
  }
}

var w=new l()

  

es6類聲明,class總結