class子类方法重写

47 阅读1分钟

在子类中使用与父类同名的方法,重写方法,重写后,只能调取子类的重写方法,无法调取改写的父类方法

class phone{
constructor(brand,price){
this.brand=brand;
this.price=price;
}
call(){
console.log("我可以打电话");
}
}

class smartphone extends phone{
constructor(brand,price,color,size){
super(brand,price);
this.color=color;
this.size=size;
}
photo(){
console.log("拍照");
}
playgame(){
console.log("玩游戏");
}
call(){
console.log("我可以打视频");
}
}

const xiaomi=new smartphone('小米',888,'黑色','4.5');
console.log(xiaomi);