Firebug 控制台中的对象

2024-01-08

这是我发布的问题的扩展here https://stackoverflow.com/questions/11750145/javascript-trouble-using-for-in-to-iterate-through-an-object.

I'm having trouble manipulating js Objects, and I think it has something to do with scope or how the Objects are populated. I'm trying to use Firebug to get to the bottom of the issue, and did find one discrepancy that I can't explain. Does anyone know why sometimes Console will show an object like this: enter image description here

显示对象内容的地方

有时像这样:

对象看起来好像是空的

However, the object isn't empty - when I click on the Object { } in the above screenshot, I'm taken to the DOM inspector, which sure enough shows the contents of that object: enter image description here

不用说,它适用于第一种方式(其中我对对象的键/值进行硬编码),但不适用于第二种方式(其中它们是动态添加的)。我在想,如果我能弄清楚为什么控制台以不同的方式显示这两个看似相似的对象,我也许能够在我的代码中找到问题的根源。如果问两次类似的问题是不好的形式,我深表歉意,但我认为这是一个特定于 Firebug 的问题,另一个与 javascript 相关......


SOLVED回想起来确实很简单,我认为@amnotiam 的最后评论走在了正确的轨道上。发生的事情是我正在打电话console.log() after对象已创建,但是before已添加任何值。当我单击它在 DOM 中检查它时,所有值都已添加。

有关原始帖子答案的更多详细信息HERE https://stackoverflow.com/questions/11750145/javascript-trouble-using-for-in-to-iterate-through-an-object.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Firebug 控制台中的对象 的相关文章

随机推荐