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()
相关文章
相关标签/搜索