首页 > 其他 > 详细

es6类声明,class总结

时间:2018-04-04 17:27:22      阅读:204      评论:0      收藏:0      [点我收藏+]

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总结

原文:https://www.cnblogs.com/huangqiming/p/8717960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!