回答編集履歴
1
「prototypeによる書き方は全て除く」を読み落としていたので、③を再回答
answer
CHANGED
@@ -51,4 +51,31 @@
|
|
51
51
|
satoWallet.income( tanakaWallet.payment(500) );
|
52
52
|
alert( tanakaWallet.show() );
|
53
53
|
alert( satoWallet.show() );
|
54
|
+
```
|
55
|
+
|
56
|
+
### 「prototypeによる書き方は全て除く」を読み落としていたので、③を再回答
|
57
|
+
```js
|
58
|
+
let wallet = class{
|
59
|
+
constructor(name, cash){
|
60
|
+
this.name = name;
|
61
|
+
this.cash = cash;
|
62
|
+
}
|
63
|
+
show(){
|
64
|
+
return `${this.name}のお財布には${this.cash}円入っています。`
|
65
|
+
}
|
66
|
+
payment(x){
|
67
|
+
this.cash -= x;
|
68
|
+
return x;
|
69
|
+
}
|
70
|
+
income(x){
|
71
|
+
this.cash += x;
|
72
|
+
return x;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
let tanakaWallet = new wallet('田中', 1000);
|
77
|
+
let satoWallet = new wallet('佐藤', 1000);
|
78
|
+
satoWallet.income( tanakaWallet.payment(500) );
|
79
|
+
alert( tanakaWallet.show() );
|
80
|
+
alert( satoWallet.show() );
|
54
81
|
```
|