class

42 阅读1分钟

class

引入类概念,作为对象的模板,通过class,定义类。

function phone(brand,price){
this.brand=brand;
this.price=price;
}

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

实例化对象

let huawei=new phone('华为'5999);
huawei.call();
console.log(huawei);

------------

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

let onplus=new phone('1+',1000);
console.log(onplus);