Bug in console.log? [duplicate] Bug in console.log? [duplicate] google-chrome google-chrome

Bug in console.log? [duplicate]


My view is that this is a horrendously irritating 'feature' that I really wish I could turn off, it makes debugging a nightmare, not knowing at which point in time something may have updated an object, whilst trying to establish exact object state at a give point in the code. The feature could be useful for 'watch points' etc, but not in something called a 'LOG' (the clue is in the name).

Consider this code fragment:

var person = {'name':'Tom'};console.log( person);  //output the entire object variableperson.name = 'Thomas';//the output is an object, whose 'name' value is 'Thomas', even though the log statement was placed before the value was changed to 'Thomas'.

AND THEN:

var person = {'name':'Tom'};console.log( person.name);    //changed to output a string variableperson.name = 'Thomas';//the output here, however, has not dynamically updated and correctly outputs 'Tom'


this is a known bug (50316) that gets reported again and again because people don't take a look at the bugtracker before reporting:

sadly, theres no information about if/when this will get solved. until that moment, you'll need to clone objects before passing them to console.log().


Sounds to me more like a race condition than anything else. Since you are only passing a reference to console.log(), the value it refers it has likely changed value by the time it is actually logged. Then when you use setTimeout(), the value changes after it has been logged. Instead of passing a reference to console.log(), pass a clone of the value.