Appframe Knowledge Base

1 hits

How to create an empty object that does not inherit from anything in JavaScript

//Called without any parameters creates a totally empty object
// (even without the Object prototype if your browser supports it)
var vEmptyObject = af.common.createObject();
// vEmptyObject.hasOwnProperty will not be present here in modern browsers

// You can also create an object based on another object
var vOtherObject = { foo: 1, bar: 2 };
// Returns an object with the keys and values of the object passed in

// Can also be used to make an array into an object
var vArray = ["a", "b", "c"];
// Returns the array as an object {0: "a", 1: "b", 2: "c"}

common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)