Objects in Firebug console

[亡魂溺海] 提交于 2020-01-04 06:57:10

问题


This is an extension of a question I have posted here.

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:

Where it shows the contents of the Object

And sometimes like this:

Where it looks as if the Object is empty

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:

Needless to say, it works the first way (in which I hard-coded the object's keys/values) but not the second way (in which they are dynamically added). I'm thinking if I can figure out why Console displays these two seemingly similar Objects differently, I may be able to get the bottom of the problem in my code. And I apologize if asking a similar question twice is bad form, but I figured this is a Firebug-specific question and the other is javascript related...


回答1:


SOLVED Really quite simple in retrospect, and I think @amnotiam was on to the right track with his last comment. What is happening is that I'm calling console.log() after the Object is created, but before any values have been added. By the time I click on it to inspect it in the DOM, all the values have been added.

More details on the answer to original post HERE.



来源:https://stackoverflow.com/questions/11763932/objects-in-firebug-console

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