回答編集履歴

1

「prototypeによる書き方は全て除く」を読み落としていたので、③を再回答

2018/04/27 05:20

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア36074

test CHANGED
@@ -105,3 +105,57 @@
105
105
  alert( satoWallet.show() );
106
106
 
107
107
  ```
108
+
109
+  
110
+
111
+ ### 「prototypeによる書き方は全て除く」を読み落としていたので、③を再回答
112
+
113
+ ```js
114
+
115
+ let wallet = class{
116
+
117
+ constructor(name, cash){
118
+
119
+ this.name = name;
120
+
121
+ this.cash = cash;
122
+
123
+ }
124
+
125
+ show(){
126
+
127
+ return `${this.name}のお財布には${this.cash}円入っています。`
128
+
129
+ }
130
+
131
+ payment(x){
132
+
133
+ this.cash -= x;
134
+
135
+ return x;
136
+
137
+ }
138
+
139
+ income(x){
140
+
141
+ this.cash += x;
142
+
143
+ return x;
144
+
145
+ }
146
+
147
+ }
148
+
149
+
150
+
151
+ let tanakaWallet = new wallet('田中', 1000);
152
+
153
+ let satoWallet = new wallet('佐藤', 1000);
154
+
155
+ satoWallet.income( tanakaWallet.payment(500) );
156
+
157
+ alert( tanakaWallet.show() );
158
+
159
+ alert( satoWallet.show() );
160
+
161
+ ```