在類里面添加靜態方法可以使用staitc這個關鍵字,staitc就是不需要實例化類就可以使用的方法
class Chef{ constructor(food){ this.food = food; thid.dish = []; } //getter get menu(){ return this.dish } //setter set menu(dish){ this.dish.push(dish) } staitc cook(food){ console.log(this.food) } } Chef.cook('tomato') //tomato
cook是個靜態方法,不需要實例化就可以直接使用,這里得到的結果就是cook里面做的事