【问题标题】:DOM prototype chain traversal in FireFoxFireFox中的DOM原型链遍历
【发布时间】:2012-04-18 06:40:43
【问题描述】:

Chrome 为 div 提供了以下原型链:

element = document.getElementById("test")
<div id=​"test">​…​</div>​
element.__proto__
HTMLDivElement
element.__proto__.__proto__
HTMLElement
element.__proto__.__proto__.__proto__
Element
element.__proto__.__proto__.__proto__.__proto__
Node
element.__proto__.__proto__.__proto__.__proto__.__proto__
Object
element.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__
null

在 Firefox 的情况下,我得到如下所示的内容,而 xpconnect 看起来像一些桥梁。 我在 Mozilla 文档中得到了相同的原型链图片(与 Chrome 相同)。这里我的问题是如何通过遍历 HTMLDiv 元素来获取 Node 对象?如果我们有 div 元素,有人可以编写给我 Node 对象或任何其他对象(如 HTMLElement)的 js 代码吗?

图像看起来与 chrome 模型相同,但我需要代码来遍历这棵树:)

提前致谢。

Link of image

var element = document.getElementById("test");
element.toString();
[object HTMLDivElement]
element.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.__proto__.__proto__.toString();
[object DOM Constructor.prototype]
element.__proto__.__proto__.__proto__.__proto__.__proto__.toString();
[object Object]

我相信 element.constructor.prototype.proto 和 element.proto 是一回事。

【问题讨论】:

  • 你想达到什么目的?
  • 我想在链的每一步比较chrome和firefox的属性。
  • Firefox 中有一个known bug 导致toString 返回[xpconnect wrapped native prototype]

标签: javascript firefox dom google-chrome


【解决方案1】:

一个对象的 proto 是一个对象,它当然有一个对象的 proto 引用,所以它们都是一样的

【讨论】:

    猜你喜欢
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多