2011-08-11 44 views
3

您可以通過多種方式在JavaScript中創建對象:從哪個版本開始,IE可以支持Object.create(null)?

// creates an object which makes the Object, prototype of data. 
var data1 = new Object(); 

// Object literal notation; Object still is the prototype of data2. 
var data2 = {}; 

// anotherObject is now the prototype of data3. 
var data3 = Object.create(anotherObject); 

/* data3 is an object which can be verified bye typeof operator, 
    however, it now has no prototype and you can 
    build everything from scratch. */ 
var data3 = Object.create(null); 

但我不知道是哪個IE版本支持最後一種方法,即Object.create(null)方法?

+0

又是怎麼回事使用內聯對象初始化的'{}'或對象的構造'new Object()',並且不要因IE特定的行爲而失去時間嗎? –

+0

@Matias,我想要一個沒有原型的對象,你不能用'{}'或'new Object )'。 –

+0

你不能在JavaScript中沒有沒有原型的對象,因爲這種腳本語言中對象的原型因果關係就是propotype!:D JavaScript不是OOP,它是「原型導向的」 –

回答

5

查看維基百科的JavaScript version history。如果您發現1.8.5版本 - 這是您可以找到此對象工廠方法的語言版本 - 第9版Internet Explorer是支持該工具的版本。

ECMAScript 5 Compatibility Table也有這方面的信息。

您也可以嘗試使用自己微軟的IE瀏覽器的虛擬機(可從here之一,或者很老版本的IE,Multiple IE的。

+0

感謝您的鏈接。但是,它並沒有談論對象工廠方法,並且我在IE8中對其進行了檢查。有效。 'Object.create(null);'適用於IE8。 –

+0

檢查我的更新。 –

+1

我不知道它爲什麼在你的IE8中工作,它不在我的。我檢查了MSDN。 「Internet Explorer 8標準模式和Quirks模式不支持Object.create函數(JavaScript)。」 – Andy