javascript - 奇怪的是,window.document 没有返回理想情况下应该返回的正确对象。为什么?

标签 javascript html object ecmascript-6

情况一:(任何一般对象)

Obj1 = {
 name: "Jack",
 age: 21,
 address: {
  city: "New York",
  street: "Black Street",
  house_no: 39
 }
}

现在,在 console.log(Obj1.address) 我会得到:

 {
  city: "New York",
  street: "Black Street",
  house_no: 39
 }

案例二:Window.document

应用相同的逻辑 - 首先我会做 console.log(window) ,然后console.log(window.document) 。但是,现在我没有得到 window.document 的正确结构(理想情况下我应该得到),而是得到“dom-struct”(理想情况下我不应该得到)。

现在,有人可以告诉我为什么会发生这种情况吗?如何在 window.document 中获得正确的结构而不是 html dom?

console.log(窗口);

enter image description here

console.log(window.document);

enter image description here

Now, Can someone please help me understand the issue of why 'window.document' is not providing proper structure of object -- which it should?

最佳答案

当您 console.log 任何 DOM 元素时,Chromium 将在控制台中显示该元素的 HTML 结构。如果您想检查对象的 Javascript 属性,则必须使用 console.dir:

enter image description here

(这样做的主要缺点是 console.dir 只接受一个对象作为参数,但 console.log 可以一次记录多个参数)

关于javascript - 奇怪的是,window.document 没有返回理想情况下应该返回的正确对象。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60703668/

相关文章:

javascript - Node.js 单线程机制

Java地址簿。如何防止代码中出现重复的联系人?

javascript - 如何确定某物是数组还是对象?

php - Laravel 中将对象转换为数组

javascript - 如何使用gulp重命名index.html中脚本的原始文件?

javascript - 尝试使用 jasmine 和 angular 时出错

javascript - 从字符串末尾匹配多个实例

html - 将 4 边立方体转换为 3 边

css - 通过响应缩放保持 iframe 比率

html - 导航菜单 : css vertical centering