es6類聲明,class總結

一、class的基本寫法javascript

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()

二、繼承classjava

class l extends a {
  calc(){
    console.log(super.calc())
    return this.a-this.b
  }
}var w=new l()
相關文章
相關標籤/搜索