This JavaScript code...
var o = {};
console.dir(o);
o.foo = "bar";
console.dir(o);
...results in the same interactive tree output shown twice:
This issue is discussed as a bug here on Stack Overflow, logged as a Chromium bug and WebKit (and I imagine elsewhere).
I understand the implementation reason that this is the case, but it makes debugging stateful objects hard (without using the interactive debugger). What strategy do you use for logging in such situations, where you need to see the differing states of the object in each log call? JSON.stringify()
? Is there a console method for serialization that can be used?