Consecutive calls to console.log produce inconsistent results

后端 未结 2 1495
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 05:44

Ok, I\'m completely dumbfounded by this. (and I might be overlooking something obvious but...)

I have 2 consecutive calls to console.log. There isn\'t anything else b

相关标签:
2条回答
  • 2020-12-18 06:07

    Well, here's the answer for those that stumble upon this.

    Short Answer

    Console.log shows deep mutable objects at the last state of execution, not at the state when console.log was called.

    More details

    Basically, when working with mutable deep objects, Console.log stores the reference to said object instead of storing an object clone.

    Since there is a time gap between storing and visualization, when you click the arrow for further inspection what you're seeing is actually the current state of the object and not the the state of the object when console.log was called.

    One way to always make sure you're using an "object snapshot" is to call Json.stringify or use console.dir when available.

    0 讨论(0)
  • 2020-12-18 06:17

    Weird. Is it an ECMA 5 object that has a weird getter? Still wouldn't make sense for the plain $state call. I assume there's not just something broken with your GC...

    Are you sure these are the calls being logged?

    0 讨论(0)
提交回复
热议问题