Elisabeth
Elisabeth

Reputation: 21206

Nested arbitrary object does not work in javascript

Why does this not work? I get an error that this action is not supported by my IE9.

var data = new { selectedUnitKey: { value1: 1, value2: 2} }

Upvotes: 1

Views: 43

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382150

Remove the new :

var data = { selectedUnitKey: { value1: 1, value2: 2} }

From the MDN :

The new operator creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

You use new like this when you define your "class" :

function SomeClass(unitKey) {
     this.selectedUnitKey = unitKey;
}
var data = new SomeClass({ value1: 1, value2: 2});

Upvotes: 3

Related Questions