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?
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?
-
And what about of using inline object initializer
{}
or Object constructornew Object()
, and don't lose your time with IE-specific behaviors? – Matías Fidemraizer Commented Aug 11, 2011 at 9:11 -
@Matias, I want to have an object with no prototype. You can't achieve that with
{}
ornew Object()
. – Saeed Neamati Commented Aug 11, 2011 at 9: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 Commented Aug 11, 2011 at 9:30
-
@Matias, turns out that you can, 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 Commented Aug 11, 2011 at 9:45
1 Answer
Reset to default 6Check 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.