Chrome displays different object contents on expand

我的梦境 提交于 2019-11-27 16:16:49

The object you see in the console is a snapshot of the object at a particular point in time - the time when you logged it. When you expand the object, it will evaluate the properties again.

In the example below, I have created an object with two array properties. I logged it the console, and then I added a third property, c to it.

Only the first two properties are showing still, even though I just added a third property. After expanding the object in the console, I can see the third one. It is the latest state of the object.

If you hover over the little blue i icon, it explains what it has done:

Value below was evaluated just now.

@Gideon Pyzer is right. the properties were caculated and added after expanding the object in the console.

Just add one line code above your debug code and reopen the chrome dev tool, you will see the differences.

obj = Object.freeze(obj);  //add this line before your console.log
console.log(obj);

Before:

After:

one similar question of mine: Why can't I access the attr of the javascript object shown in chrome dev tool

You can clone your object to prevent re-evaluate.

console.log(Object.assign({}, obj));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!