4

You can create an object in JavaScript in many ways:

// 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); 

But I don't know which versions of IE support the last method, i.e. Object.create(null) method?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • And what about of using inline object initializer `{}` or Object constructor `new Object()`, and don't lose your time with IE-specific behaviors? – Matías Fidemraizer Aug 11 '11 at 09:11
  • @Matias, I want to have an object with no prototype. You can't achieve that with `{}` or `new Object()`. – Saeed Neamati Aug 11 '11 at 09:26
  • You can't have an object without prototype in JavaScript, because the archetype of an object in this scripting language causally is the propotype! :D JavaScript isn't OOP, it's "prototype-oriented". – Matías Fidemraizer Aug 11 '11 at 09:30
  • @Matias, [turns out that you can](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create), and that's exactly what I want. To have `null` as the prototype of my object, or in other words, to have no prototype at all. – Saeed Neamati Aug 11 '11 at 09:45

1 Answers1

6

Check Wikipedia's JavaScript version history. If you find 1.8.5 version - and this is the language version where you find this Object factory method available - 9th version of Internet Explorer is the one supporting that.

The ECMAScript 5 Compatibility Table also has this information.

You can also try for yourself using one of Microsoft's IE virtual machines (available from here or, for very old versions of IE, Multiple IE.

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
  • 1
    thanks for the link. However, it doesn't talk about Object factory method, and I checked it in IE8. It worked. `Object.create(null);` works in IE8. – Saeed Neamati Aug 11 '11 at 10:01
  • 1
    I don't know why it worked in yours IE8, it doesn't in mine. And I checked in MSDN. "Object.create Function (JavaScript) is not supported in Internet Explorer 8 standards mode and Quirks mode." – Andy May 19 '12 at 23:50
  • @Andy I don't know really, because at the time I was answering OP I did some research and I gave him these links, but I didn't tried it in IE8 myself. Maybe you're right. – Matías Fidemraizer May 20 '12 at 13:12
  • @Andy or maybe I checked it in IE8 myself... but actually I don't remember what I did a lot of months ago haha – Matías Fidemraizer May 20 '12 at 13:13
  • ES5 Object.create is not supported in IE8, of course if you're trying it with a hacked browser or in emulated mode, you won't notice it: http://kangax.github.io/es5-compat-table/#Object.create –  Apr 14 '13 at 08:24