且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

连续通话CONSOLE.LO***生不一致的结果

更新时间:2023-02-06 09:51:10

嗯,这里是为那些在这一点,绊倒了答案。

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

CONSOLE.LOG有深可变对象在执行的最后状态,不是当的console.log被称为在状态

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

基本上,可变深对象时,CONSOLE.LOG存储引用说的对象,而不是存储对象的克隆。

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

既然有存储和可视化,当你点击进行进一步的检查,你看到的箭头之间的时间差距实际上对象的当前状态并不会在状态时的console.log被称为对象的

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.

一个方法始终确保您使用的是对象快照是调用 Json.stringify 或使用 console.dir 时可用。

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