在FireFox中进行DOM原型链遍历

时间:2012-04-04 14:22:39

标签: javascript firefox dom google-chrome

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元素,有人可以写js代码给我Node对象或任何其他对象,如HTMLElement吗?

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

提前致谢。

Link of image

enter image description here

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 和元素。 proto 是一回事。

1 个答案:

答案 0 :(得分:-1)

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