2012-04-04 143 views
0

鉻給人follwing原型鏈一個div:DOM原型鏈遍歷

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嗎?

圖像看起來相同的鍍鉻模型,但我需要的代碼來遍歷這棵樹:)

在此先感謝。

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。 原型和元素。 原型是同樣的事情。

+0

你到底想達到什麼目的? – 2012-04-04 14:27:34

+0

我想在鏈的每一步比較Chrome和Firefox的屬性。 – 2012-04-04 14:29:18

+0

在Firefox中有一個[已知錯誤](https://bugzilla.mozilla.org/show_bug.cgi?id=684601),導致'toString'返回'[xpconnect包裝的本機原型]'。 – 2012-04-04 15:14:33

回答

-1

一個對象的是一個對象,這當然有裁判一個對象,所以他們都是一樣的