您可以通過多種方式在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)
方法?
又是怎麼回事使用內聯對象初始化的'{}'或對象的構造'new Object()',並且不要因IE特定的行爲而失去時間嗎? –
@Matias,我想要一個沒有原型的對象,你不能用'{}'或'new Object )'。 –
你不能在JavaScript中沒有沒有原型的對象,因爲這種腳本語言中對象的原型因果關係就是propotype!:D JavaScript不是OOP,它是「原型導向的」 –