对象声明:字符串作为键有区别吗? [英] Object declarations: Do strings as keys make a difference?
本文介绍了对象声明:字符串作为键有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 stackoverflow 上有一些关于 JSON 是对象文字表示法的子集的问题.但我找不到我的特定问题的答案.
There are some questions floating around here on stackoverflow about JSON being a subset of the Object Literal Notation. But I couldn't find an answer to a specific question of mine.
有什么区别吗
var obj = {keyName : "value"};
和
var obj = {"keyName" : "value"};
在 JavaScript 中?
in JavaScript?
推荐答案
是的.不同之处在于后者的文件大小将大两个字节,以解决代码中两个额外的 "
字符.
Yes. The difference is that the file size of the latter will be two bytes larger to account for the two extra "
characters in your code.
否则不会,您提供的两个示例对象之间没有区别.
Otherwise no, there's no difference between the two example objects you've given.
var obj = {keyName : "value"};
obj.keyName; /* "value" */
obj["keyName"]; /* "value" */
var obj = {"keyName" : "value"};
obj.keyName; /* "value" */
obj["keyName"]; /* "value" */
这篇关于对象声明:字符串作为键有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文