P粉0233267732023-08-28 15:10:01
console.log()
will pass a reference to the object, so the value in the console will change as the object changes. To avoid this you can:
console.log(JSON.parse(JSON.stringify(c)))
P粉7953113212023-08-28 12:26:58
Pointy's answer provides good information, but it is not the correct answer to this question.
The behavior described by the OP was part of a bug first reported in March 2010 and patched for Webkit in August 2012, but has not yet been integrated into Google Chrome as of this writing. Behavior depends on whether the console debug window is open
or closed when passing an object literal to console.log() .
Excerpt from the original bug report (https://bugs.webkit.org/show_bug .cgi?id=35801):
Chromium Developer Response:
A lot of complaints ensued, which eventually led to a bug fix.
Changelog description for patch implemented in August 2012 (http://trac.webkit.org/changeset/ 125174):