2

How can I stop Chrome from trying to intelligently update my objects that I console.log which have been altered and logged in quick succession?

I can't seem to reproduce on jsfiddle, but if I do something like this with very complex objects

var obj1 = {
    a: 1
}
var obj2 = {
    a: 2
}
console.log(obj1);
$.extend(true, obj1, obj2)
console.log(obj1);

I will see that obj1.a = 2 in both logs. I know this as a fact as others have told me in other questions that this happens.

Is there any way to turn this off?

BarryBones41
  • 1,361
  • 1
  • 13
  • 30
  • If not, you could `JSON.stringify` before logging to get the snapshot. – spender Feb 11 '16 at 16:24
  • I just tried your code and I get different values `Object {a: 1} ,Object {a: 2}`. What is the output you're getting and what you expect ? – 11thdimension Feb 11 '16 at 16:28
  • @11thdimension The behavior only manifests with objects with one nesting level if the console is closed. (Try wrapping the code in a `setTimeout(function(){...}, 5000)` call and closing the console and waiting.) If you don't want to close the console, you can also reproduce the issue with a nested object, e.g., `console.log([obj1]);` – apsillers Feb 11 '16 at 16:31
  • 1
    @apsillers Got it, it's happening with the Arrays, seems like it's logging reference to the object. Probably related to this SO Entry http://stackoverflow.com/questions/24175017/google-chrome-console-log-inconsistency-with-objects-and-arrays – 11thdimension Feb 11 '16 at 16:43
  • That's frustrating.. a bug that is fixed but not implemented. The amount of hours I've wasted trying to understand why something isn't working when it is.. ugh! – BarryBones41 Feb 11 '16 at 16:44

0 Answers0