我在想,也许我错过了什么在JavaScript中的我只是拿起了。
我想这code在Chrome的控制台:
A = [];
a.name =测试;
JSON.stringify(一);
//返回值[]
A =新的对象();
a.name =测试;
JSON.stringify(一);
//返回值{名:测试}
有什么区别? 我认为新的对象()是Microsoft JScript中的事情吗?我在想什么? 必须错过了一些东西在一个规范的地方。谢谢。
解决方案 A =新的对象()
和
A = []
是不等价的。但是,
A = {}
和
A =新的对象()
是
I'm thinking maybe I missed something in JavaScript that I'm just picking up now.
I tried this code in Chrome console:
a = [];
a.name = "test";
JSON.stringify(a);
// which returns value []
a = new Object();
a.name = "test";
JSON.stringify(a);
// which returns value {"name":"test"}
What is the difference? I thought new Object() was a Microsoft JScript thing? What am I missing? Must have missed something in a spec somewhere. Thanks.
解决方案a = new Object()
and
a = []
are not equivalent. But,
a = {}
and
a = new Object()
are.