2009-01-28 115 views
1

的JavaScript代碼在不同的瀏覽器不同的效果:爲什麼有些對象在IE中沒有構造函數?下面

document.write(this.location.constructor); 
document.write("<br/>"); 
document.write(this.constructor); 
document.write("<br/>"); 

在Chrome中,頁面有:

function Location() { [native code] } 
function DOMWindow() { [native code] } 

在Firefox中,頁面有:

[object Location] 
[object Window] 

在IE8的頁面有:

undefined 
undefined 

Chrome和Firefox的區別可能與toString()的實現不同。我只是不明白爲什麼這兩個對象的構造函數在IE中是undefined。如果他們的構造函數是未定義的,那麼他們的原型呢?他們也是undefined

回答

1

使用IE8調試控制檯,我沒有問題使用您給出的代碼作爲例子。

我的結果...

[object Location] 
[object Window] 

你肯定有其他東西沒有引起這些失敗?

+0

我正在使用IE 8.0.6001.18372。 有趣的是,如果我加載一個本地html與「document.write(this.constructor)」,它是未定義的;如果我只是在URL輸入欄中輸入「javascript:this.constructor」,它會顯示[object Window]。 – 2009-01-29 03:55:20

相關問題