1.类class
class Phone{
constructor(branhd,price){
this.brand=brand
this,price=price
}
callsb(){
console.log("我可以打电话")
}
}
let onePlus=new Phone("onep",999)
用类名.xxx定义的属性(Phone.size='5.5')不能通过实例.xxx调用,称此为静态成员。只有定义在原型上的成员才可以被实例调用(Phone.prototype.size='5.5')
ES5继承:
ES6的类继承
子extends父,构造方法里面写super()传参给父
get、set
类的内部定义函数不要用逗号隔开,也不要用function关键字
class F{
constructor(name){
this.name=name
}
fn(){
alert("1")
}
}
class S extends F{
constructor(name,age){
super(name) //放第一行
this.age=age
} //函数之间不用逗号合开
f1(){
super.fn() //子函数通过super调用父函数中的函数
}
}
let son=new S("z",12)
son.f1()