ES5构造函数继承

42 阅读1分钟
function Phone(brand,price){
this.brand=brand;
this.price=price;
}

phone.prototype.call=fucntion(){
console.log("我可以打电话");
}

function smartphone(brand,price,color,size){
phone.call(this,brand,price);
this.color=color;
this.size=size;
}

smartphone.prototype=new phone;
smartphone.prototype.constructor=smartphone;


smartphone.prototype.photo=function(){
console.log("我可以拍照");
}

smartphone.prototype.playgame=function(){
console.log("我可以玩游戏");
}

const chuizi=new smartphone('锤子',2333,'黑色','5.5');
console.log(chuizi);