class Chef {
constructor(food) {
this.food = food;
this.data;
}
cook() {
console.log('我在做饭' + this.food);
}
set menu(data) { //set方法
this.data = data;
}
get menu() { //get方法
return this.data;
}
}
let c = new Chef('米饭');
c.cook();
c.menu = 500;
console.log(c.menu)
网友评论