用class实现继承
class Phone{
constructor(brand){
this.brand = brand;
}
call(){
console.log("我可以打电话!!");
}
}
class SmartPhone extends Phone {
constructor(brand, color){
super(brand);
this.color = color;
}
photo(){
console.log("拍照");
}
call(){
console.log('我可以进行视频通话');
}
}
const xiaomi = new SmartPhone('小米','黑色',);
xiaomi.call();
xiaomi.photo();
ES5的继承
function Phone(brand){
this.brand = brand;
}
Phone.prototype.call = function(){
console.log("我可以打电话");
}
function SmartPhone(brand, color){
Phone.call(this, brand);
this.color = color;
}
SmartPhone.prototype.__proto__ = Phone.prototype;
SmartPhone.prototype.photo = function(){
console.log("我可以拍照")
}
const chuizi = new SmartPhone('锤子','黑色');
console.log(chuizi);