質問編集履歴
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,23 +38,22 @@
|
|
38
38
|
console.log(array1); // [empty, empty, empty ]
|
39
39
|
console.log(array2); // [undefined, undefined, undefined]
|
40
40
|
|
41
|
-
// CodePen だと empty ではなく undefined と表示されてしまう。
|
41
|
+
// 1) CodePen だと empty ではなく undefined と表示されてしまう。
|
42
|
-
//
|
42
|
+
// console.log(array1);
|
43
|
-
//
|
43
|
+
// -> [undefined, undefined, undefined]
|
44
44
|
|
45
|
-
// empty は、存在しない。
|
45
|
+
// 2) empty は、存在しない。
|
46
|
-
//
|
46
|
+
// console.log(empty);
|
47
|
-
//
|
47
|
+
// -> Uncaught ReferenceError: empty is not defined
|
48
48
|
|
49
|
-
// empty は null とも違いそう。
|
49
|
+
// 3) empty は null とも違いそう。
|
50
50
|
|
51
51
|
|
52
52
|
|
53
53
|
|
54
|
-
// 挙動
|
55
|
-
//
|
54
|
+
// 4) インデックスを指定して empty を取得しようとすると
|
56
|
-
//
|
55
|
+
// empty が undefined になる。
|
57
|
-
//
|
56
|
+
// このとき undefined との厳密等価演算は true になる。
|
58
57
|
console.log(array1[0]); // undefined
|
59
58
|
console.log(array2[0]); // undefined
|
60
59
|
console.log(array1[0] === array1[1]); // true
|
@@ -73,7 +72,7 @@
|
|
73
72
|
console.log(Object.keys(array2)) // => [0, 1, 2]
|
74
73
|
|
75
74
|
// 結果 map の結果も異なる。
|
76
|
-
console.log(array1.map(()=>3)); // [
|
75
|
+
console.log(array1.map(()=>3)); // [empty, empty, empty]
|
77
76
|
console.log(array2.map(()=>3)); // [3, 3, 3]
|
78
77
|
|
79
78
|
/* ここで... */
|
@@ -82,7 +81,7 @@
|
|
82
81
|
array1[2] = 2;
|
83
82
|
|
84
83
|
// 以下のようになる。
|
85
|
-
console.log(array1); // [0,
|
84
|
+
console.log(array1); // [0, empty, 2]
|
86
85
|
console.log(Object.keys(array1)) // => [0, 2]
|
87
|
-
console.log(
|
86
|
+
console.log(array1.map(()=>3)); // [3, empty, 3]
|
88
87
|
```
|
1
ご指導いただいた内容を元に追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,4 +22,67 @@
|
|
22
22
|
> [applyとcallの使い方を丁寧に説明してみる](http://taiju.hatenablog.com/entry/20100515/1273903873)
|
23
23
|
|
24
24
|
何か参考になるページ等ご教示いただけましたら、幸いでございます。
|
25
|
-
どうぞ、よろしくお願いいたします。
|
25
|
+
どうぞ、よろしくお願いいたします。
|
26
|
+
|
27
|
+
---
|
28
|
+
ご回答いただき、誠にありがとうございます。
|
29
|
+
ご指導いただいた内容を元に再度整理いたしまいた。
|
30
|
+
|
31
|
+
上記は CodePen での実行結果
|
32
|
+
以下は Chrome での実行結果
|
33
|
+
```js
|
34
|
+
var array1 = Array(3); // new Array(3); と等価
|
35
|
+
var array2 = Array.apply(null, Array(3));
|
36
|
+
|
37
|
+
//
|
38
|
+
console.log(array1); // [empty, empty, empty ]
|
39
|
+
console.log(array2); // [undefined, undefined, undefined]
|
40
|
+
|
41
|
+
// CodePen だと empty ではなく undefined と表示されてしまう。
|
42
|
+
// console.log(array1);
|
43
|
+
// -> [undefined, undefined, undefined]
|
44
|
+
|
45
|
+
// empty は、存在しない。
|
46
|
+
// console.log(empty);
|
47
|
+
// -> Uncaught ReferenceError: empty is not defined
|
48
|
+
|
49
|
+
// empty は null とも違いそう。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
// 挙動
|
55
|
+
// インデックスを指定して empty を取得しようとすると
|
56
|
+
// empty が undefined になる。
|
57
|
+
// このとき厳密等価演算は true になる。
|
58
|
+
console.log(array1[0]); // undefined
|
59
|
+
console.log(array2[0]); // undefined
|
60
|
+
console.log(array1[0] === array1[1]); // true
|
61
|
+
|
62
|
+
// 配列の型も
|
63
|
+
console.log(typeof(array1)); // object
|
64
|
+
console.log(typeof(array2)); // object
|
65
|
+
|
66
|
+
// その中の要素の型も同じ
|
67
|
+
console.log(typeof(array1[0])); // undefined
|
68
|
+
console.log(typeof(array2[0])); // undefined
|
69
|
+
console.log(typeof(array1[0]) == typeof(array2[0])) // true
|
70
|
+
|
71
|
+
// keys は異なる
|
72
|
+
console.log(Object.keys(array1)) // => []
|
73
|
+
console.log(Object.keys(array2)) // => [0, 1, 2]
|
74
|
+
|
75
|
+
// 結果 map の結果も異なる。
|
76
|
+
console.log(array1.map(()=>3)); // [undefined, undefined, undefined]
|
77
|
+
console.log(array2.map(()=>3)); // [3, 3, 3]
|
78
|
+
|
79
|
+
/* ここで... */
|
80
|
+
// ここで次のようにすると
|
81
|
+
array1[0] = 0;
|
82
|
+
array1[2] = 2;
|
83
|
+
|
84
|
+
// 以下のようになる。
|
85
|
+
console.log(array1); // [0, undefined, 2]
|
86
|
+
console.log(Object.keys(array1)) // => [0, 2]
|
87
|
+
console.log(array2.map(()=>3)); // [3, undefined, 3]
|
88
|
+
```
|