ES6—45:子类对父类方法的重写
代码示例class Father {
constructor(name,price) {
this.name = name;
this.price = price;
};
call() {
console.log("手机可以打电话!");
};
};
class Son extends Father {
constructor(name,price,color,size) {
super(name,price);
this.color = color;
this.size = size;
};
photo() {
console.log("手机可以拍照");
};
call() {
console.log("这是子类的函数");
};
};
const xiaomi = new Son("红米K30","4999","荣耀黑","6.7英寸");
console.log(xiaomi);
xiaomi.call();
实现效果
https://blog.51cto.com/u_13162410/4843183
页:
[1]