为什么这不起作用?我收到一条错误消息,指出我的 IE9 不支持此操作。
var data = new { selectedUnitKey: { value1: 1, value2: 2} }
最佳答案
删除新的
:
var data = { selectedUnitKey: { value1: 1, value2: 2} }
来自 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.
当你定义你的“类”时,你可以像这样使用 new :
function SomeClass(unitKey) {
this.selectedUnitKey = unitKey;
}
var data = new SomeClass({ value1: 1, value2: 2});
关于javascript - 嵌套的任意对象在 javascript 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13947858/