es6 class

1定义类

 class Phone{

 construct(name,age){

this.name=name;

this.age=age

}

static hh=’丽丽‘;//static 仅仅自己使用,不能给子类使用,也不能给实例使用

static 00=function(){//static 仅仅自己使用,不能给子类使用,也不能给实例使用

}

call(){//不是简写  就必须这么写

console.log('这是自己的方法')

}

}

 

class phone extend Phone{

construct(name,age,q,b){

super(name.age);

this.q=q;

this.d=d;

}

self(){

console.log('自己的方法‘)

}

}

const   pp=new phone();

//实例可以调用父类的call方法  但是不能调用父类的同名方法(会被子类方法覆盖)

2 get  +set方法、

在class中

 get price(){

console.log('获取价格0')

}

}

 set price(newPrice){//必须有参数

console.log('设置价格被修改')

}

}

pp.price=1000;//价格被修改

 

posted @ 2020-08-11 20:44  青橙娃娃  阅读(77)  评论(0编辑  收藏  举报