回答編集履歴

1

動作根拠を追加

2018/01/27 14:48

投稿

defghi1977
defghi1977

スコア4756

test CHANGED
@@ -1,10 +1,16 @@
1
1
  以下は回答者の憶測が含まれています. 有力な根拠については不明です.
2
+
3
+
4
+
5
+ 根拠を追加
6
+
7
+
2
8
 
3
9
 
4
10
 
5
11
  ---
6
12
 
7
-
13
+ 以下は間違った解釈です.
8
14
 
9
15
  `console.log`メソッドに直接オブジェクトを指定した場合の動作に原因があるように見受けられます.
10
16
 
@@ -21,6 +27,24 @@
21
27
 
22
28
 
23
29
  であると仮定すると, 1で`console.log`の引数としてオブジェクトへの参照を渡した際に, 2の過程で初めてオブジェクトが直列化されることになります. 従って, `sort`メソッド実行前にも関わらず, `array[1]`の内容がソート済みとなっているように見えるのです.
30
+
31
+
32
+
33
+ ---
34
+
35
+ [https://developer.mozilla.org/en-US/docs/Web/API/Console/log](https://developer.mozilla.org/en-US/docs/Web/API/Console/log)
36
+
37
+ によれば
38
+
39
+
40
+
41
+ > A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output. Please be warned that if you log objects in the latest versions of Chrome and Firefox what you get logged on the console is a **reference to the object**, which is **not necessarily the 'value' of the object at the moment in time you call** console.log(), but it is the value of the object at the moment you click it open.
42
+
43
+
44
+
45
+ 要約
46
+
47
+ `console.log`で記録されるものはその時点でのオブジェクトに対する参照値であり, その時点でのオブジェクトの内部値ではない. なので, コンソールからログ内のオブジェクトにアクセスすると, その時点での値が表示される.
24
48
 
25
49
 
26
50