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
class Phone{
// 构造方法 new 的时候会自动执行
constructor(brand,price){
this.brand = brand;
this.price = price;
}
// 方法必须使用这种写法 不能使用es5 的对象完整形式
call(){
console.log('可以打电话');
}
}
let onePlue = new Phone('1+',1999);
onePlue.call();
console.log(onePlue);
我是Eric,手机号是13522679763

浙公网安备 33010602011771号