回答編集履歴
3
edit
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
applyは、`obj.func(arg1, arg2, arg3……)` を `func.apply(obj, [arg1, arg2, arg3……])` のような形式で呼び出せると考えるとわかりやすいと思います。
|
2
2
|
|
3
3
|
`var max = Math.max.apply(null, [5, 6, 2, 3, 7]);` は、`var max = Math.max(5, 6, 2, 3, 7);`と同じ意味ですし、
|
4
|
-
`Array.prototype.push.apply(vegetables,
|
4
|
+
`Array.prototype.push.apply(vegetables, ['celery', 'beetroot']);`は、`vegetables.push('celery', 'beetroot')`と同じ意味なので、期待通りの結果が得られます。
|
5
5
|
|
6
6
|
※applyとは直接関係ないので詳しく説明しませんが、`Array.prototype.push`と`['parsnip', 'potato'].push`は全く同じ関数を表しています。
|
7
7
|
(`console.log(Array.prototype.push === ['parsnip', 'potato'].push)`で確認できます)
|
2
Math.maxについて記述が間違っていたので修正
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
applyは、`obj.func(arg1, arg2, arg3……)` を `func.apply(obj, [arg1, arg2, arg3……])` のような形式で呼び出せると考えるとわかりやすいと思います。
|
2
2
|
|
3
|
-
`var max = Math.max.apply(null,
|
3
|
+
`var max = Math.max.apply(null, [5, 6, 2, 3, 7]);` は、`var max = Math.max(5, 6, 2, 3, 7);`と同じ意味ですし、
|
4
4
|
`Array.prototype.push.apply(vegetables, moreVegs);`は、`vegetables.push(moreVegs)`と同じ意味なので、期待通りの結果が得られます。
|
5
5
|
|
6
6
|
※applyとは直接関係ないので詳しく説明しませんが、`Array.prototype.push`と`['parsnip', 'potato'].push`は全く同じ関数を表しています。
|
1
edit
answer
CHANGED
@@ -3,5 +3,5 @@
|
|
3
3
|
`var max = Math.max.apply(null, numbers);` は、`var max = Math.max(numbers);`と同じ意味ですし、
|
4
4
|
`Array.prototype.push.apply(vegetables, moreVegs);`は、`vegetables.push(moreVegs)`と同じ意味なので、期待通りの結果が得られます。
|
5
5
|
|
6
|
-
※applyとは直接関係ないので詳しく説明しませんが、`Array.prototype.push`と`[
|
6
|
+
※applyとは直接関係ないので詳しく説明しませんが、`Array.prototype.push`と`['parsnip', 'potato'].push`は全く同じ関数を表しています。
|
7
|
-
(`console.log(Array.prototype.push === [
|
7
|
+
(`console.log(Array.prototype.push === ['parsnip', 'potato'].push)`で確認できます)
|