ゲッター、セッターが分かりません。
javascript
1class animal{ 2 constructor(name,count1){ 3 this.name=name; 4 this.count1=count1; 5 } 6 get count(){ 7 return this.name+"は"+this.count1+"個です"; 8 }//メソッドじゃなくてゲッター? 9 set count(i){ 10 this.count1+=i; 11 }//メソッドじゃなくてセッター? 12} 13const cat=new animal("猫",2); 14cat.count=3; 15console.log(cat.count);
ゲッター、セッターを定義したら()が必要無くなることと、普通にメソッドで出来るため、使い道が分からないです。あと、ゲッター、セッターとは具体的にどこからどこまでを指すのかも分かりません。
回答2件
あなたの回答
tips
プレビュー