class clothes{
// 构造方法 名字不能修改
constructor(name,price){
this.name = name;
this.price = price;
}
// 必须这么写,不能按照之前的es5那么些否则报错
show(){
console.log(' 衣服很漂亮!!');
}
}
// 创建对象,用new关键字去做
let newClothes = new clothes('牛仔裤','200');
console.log(newClothes);
newClothes.show();
ES6 创建类简单示例
最新推荐文章于 2022-06-22 12:41:36 发布