简体   繁体   English

chrome调试器中对象数据不一致

[英]chrome debugger inconsistency in object data

I don't understand how to interpret this debug data. 我不明白如何解释此调试数据。 I do a console.log of my object, and on the summary-line that appears in the console I am shown windows: array[0] but if I expand the object, I am shown that windows is an array of 2 items. 我为对象创建了console.log,在控制台上显示的摘要行上,我看到了windows:array [0],但是如果我扩展对象,则会看到windows是2个项目的数组。

Which is the correct one? 哪个是正确的?

My code seem to run on the summary version, ie. 我的代码似乎在摘要版本上运行,即。 windows array being empty. Windows数组为空。

Does anyone know what my problem is - why is the object presented in an inconsistent way? 有谁知道我的问题是什么-为什么对象呈现的方式不一致?

在此处输入图片说明

The object is being mutated between when you print it and when you view it. 在打印对象和查看对象之间会对其进行突变。 When it's initially logged, it's empty but by the time you open it, 2 items have been added. 最初记录时为空,但是在您打开它时,已经添加了2个项目。

var obj = { arr: [] };
console.log(obj); // Will say { arr: Array[0] }
obj.arr.push(1); // Open it up in the console after this

Basically, the dev tools print a string that's representative of it's state at the time of the log but it stores a reference to the object in the console itself. 基本上,开发人员工具会在记录日志时打印一个表示其状态的字符串,但是它将对对象的引用存储在控制台本身中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM