I'm getting different results for this fiddle on Google Chrome (14.0.835.186) and Firefox (6.0.2).
Can anyone explain the discrepancy? What is the behaviour determined by the specifications?
EDIT: On Firefox I s开发者_运维知识库ee [0]
, [0, 1]
, etc. On Chrome I see [0, 1, 2, 3, 4]
, [0, 1, 2, 3, 4]
, [0, 1, 2, 3, 4]
, etc.
I'm using Mac OS 10.6.8.
Firefox is more technically correct in this case as it outputs the state of the object at each point in the loop whereas Chrome is apparently waiting until the end of the loop to output each console.log, but I'm not aware of a standards specification that covers the console host object.
See this jsFiddle: http://jsfiddle.net/jfriend00/LRGP2/ to show that this is only console.log that has this odd behavior.
See:
- Your example with console.log before the loop
- Your example using document.write
- Bizarre console.log behaviour in Chrome Developer Tools
It's an odd behavior or the console, though I can't tell you why.
Edit: Just to make sure it's clear, this is a 'bug' in the console only, there is no problem with the way the arrays are created in Chrome.
You are logging a live object.
Try the code below (fiddle) and see the difference:
var i, test = [];
for(i=0; i<5; i++) {
test.push(i);
console.log( test.toString() ); // notice .toString() addition
}
Btw, same and aggravated example can be seen in Opera Dragongfly - arrays are even clickable and expandable there.
精彩评论