- 类的最常用实例化和继承
- 类里的方法之间不要加‘,’需要返回值的要加return
- constructor方法设置class参数
//声明一个类 class Coder{ name(val){ //console.log(val); return val; //返回值 } //不要加, niubi(val){ console.log(this.name(val)+'小伙子可以啊'+val) } constructor(a,b){//calss的参数设置 this.a=a; this.b=b; } add(){ return this.a+this.b; } }
4.调用
let websong=new Coder(); websong.niubi('牛13')
let websong_=new Coder(1,2);
console.log(websong_.add())
5.类的继承
/calss的继承 class htmlr extends Coder{ } let web_=new htmlr(1,5); console.log(web_.add());
一般开发,也就经常用这些,详细的可参考http://es6.ruanyifeng.com/#docs/class