回答編集履歴
1
質問文中にある「該当のソースコード」への言及
test
CHANGED
@@ -114,4 +114,60 @@
|
|
114
114
|
|
115
115
|
|
116
116
|
|
117
|
+
### 「該当のソースコード」について
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
質問文中にある「該当のソースコード」ですが、この場合は `Function.prototype.apply` を利用する必要がないと思います。
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
```JavaScript
|
126
|
+
|
127
|
+
function Battle () {
|
128
|
+
|
129
|
+
this.count = 0;
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
Battle.prototype.enemyAttack = function enemyAttack (enemy) {
|
136
|
+
|
137
|
+
console.log(++this.count + ': ' + enemy.name + 'の攻撃!' + enemy.name + 'のHPは' + enemy.hp + 'だ!');
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
function Enemy (name, hp) {
|
144
|
+
|
145
|
+
this.name = name;
|
146
|
+
|
147
|
+
this.hp = hp;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
var battle = new Battle,
|
154
|
+
|
155
|
+
slime = new Enemy('スライム', 8),
|
156
|
+
|
157
|
+
dragon1 = new Enemy('ドラゴン1', 100),
|
158
|
+
|
159
|
+
dragon2 = new Enemy('ドラゴン2', 200);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
battle.enemyAttack(slime); // 1: スライムの攻撃!スライムのHPは8だ!
|
164
|
+
|
165
|
+
battle.enemyAttack(dragon1); // 2: ドラゴン1の攻撃!ドラゴン1のHPは100だ!
|
166
|
+
|
167
|
+
battle.enemyAttack(dragon2); // 3: ドラゴン2の攻撃!ドラゴン2のHPは200だ!
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
|
117
173
|
Re: souta-haruran さん
|