- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
给定一个对象字面量或 jQuery(html, attributes)
对象,是否有任何规范规定必须引用保留字或将来的保留字?
或者,例如,可以将 class
设置为对象的属性名称,而无需使用引号将属性名称括起来,这种做法不违反有关标识符、属性名称的规范,还是使用保留字?
寻求关于此问题的结论性答案以避免混淆。
let objLit = {
class: 123,
var: "abc",
let: 456,
const: "def",
import: 789
}
console.dir(objLit);
jQuery("<div>012</div>", {
class: "ghi"
})
.appendTo("body");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
相关:
规范
Identifier Names are tokens that are interpreted according to the grammar given in the “Identifiers” section of chapter 5 of the Unicode standard, with some small modifications.
An Identifier is an IdentifierName that is not a ReservedWord
最佳答案
ECMAScript 5+
不,自 ECMAScript 5 以来不需要引号。原因如下:
正如您在帖子中提到的,来自 ECMAScript® 5.1 Language Specification :
7.6 Identifier Names and Identifiers
Identifier Names are tokens that are interpreted according to the grammar given in the “Identifiers” section of chapter 5 of the Unicode standard, with some small modifications. An
Identifier
is anIdentifierName
that is not aReservedWord
(see 7.6.1).[...]
Syntax
Identifier ::
IdentifierName but not ReservedWord
根据规范,ReservedWord
是:
7.6.1 Reserved Words
A reserved word is an
IdentifierName
that cannot be used as anIdentifier
.Syntax
ReservedWord ::
Keyword
FutureReservedWord
NullLiteral
BooleanLiteral
这包括关键字、 future 关键字、null
和 bool 文字。完整名单如下:
7.6.1.1 Keywords
break do instanceof typeof
case else new var
catch finally return void
continue for switch while
debugger function this with
default if throw
delete in try7.6.1.2 Future Reserved Words
class enum extends super
const export import7.8.1 Null Literals
null
7.8.2 Boolean Literals
true
false
以上(第 7.6 节)暗示 IdentifierName
可以是 ReservedWord
,并且来自 object initializers 的规范:
11.1.5 Object Initialiser
[...]
Syntax
ObjectLiteral :
{ }
{ PropertyNameAndValueList }
{ PropertyNameAndValueList , }
根据规范,PropertyName
是:
PropertyName :
IdentifierName
StringLiteral
NumericLiteral
如您所见,PropertyName
可能是 IdentifierName
,因此 ReservedWord
可以是 PropertyName
秒。这最终告诉我们,根据规范,允许使用 ReservedWord
,例如 class
和 var
作为PropertyName
不带引号,就像字符串文字或数字文字一样。
ECMAScript <5
要更深入地了解为什么在 ES5 之前的早期版本中不允许这样做,您必须查看 PropertyName
是如何定义的。根据 ECMAScript® 3 Language Specification :
PropertyName :
Identifier
StringLiteral
NumericLiteral
如您所见,PropertyName
是一个 Identifer
- 而不是 IdentifierName
,因此导致无法使用 ReservedWord
s 作为 PropertyName
s。
关于javascript - javascript对象的属性名设置保留字需要加引号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40209367/
我有一个类似 ( www.bbcurdu.com) 的网站。现在我的问题是,当我添加一个带有引号或引号的新故事时,它不会保存在数据库中。如果我删除这些逗号或引号,那么它将保存在数据库中。并正确获取和显
我正在使用(并坚持使用)以下版本的 Ruby: ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux] 我尝试了很多谷歌搜索,但找不到解决我的问题的
我有以下示例数据, 我想连接 string1 和 string2 以产生连接结果 "a""b" 使用连接函数 我在官方的microsoft excel文档中没有找到任何答案 https://suppo
我是 SQL-mySQL 方面的 super 新手,我想查询这些包含具有特定值的列的条目,但该值中已经有引号,它实际上看起来像这样,引号已经存在:“荷兰鹿特丹 Voor Land-en Volkenk
是否有一个简单的正则表达式来匹配所有 unicode 引号?还是必须像这样手动编码: quotes = ur"[\"'\u2018\u2019\u201c\u201d]" 感谢阅读。 布莱恩 最佳答案
我有下面的代码,禁止将特殊字符插入到 HTML 表单上提交的文本中。 可以看出,我需要禁用的特殊字符位于引号之间,而我需要禁用引号 " 本身,但我不能这样做,因为如果我添加另一个中间的引号然后读起来就
对于给定的输入字符串 abc,[def,ghi,ijk],lm,(no,pq,rs),[tu,vw,xy],zs,"as,as,fr"输出应该是 abc [def,ghi,ijk] lm (no,pq
下午好,快乐 4 我在处理一些 javascript 时遇到了问题....我是一个初学者,正在使用这个特定的在线示例来了解如何淡入和淡出多个引号... 我已经实现了 HTML/Javascript/C
我想在一段文本周围加上引号。文本不能超过 3 行:如果超过,我想要一个省略号(并且我仍然想要引号)。我附上我现在拥有的东西。我的解决方案使用 JS:虽然纯 CSS 解决方案是理想的,但可能的 CSS
我将它发送给一个函数,我想在下面的变量值周围加上双引号,例如 $var = "New York"(注意引号) $fq.=" + area:$state"; 所以当我回显 $state 时我想用双
这个问题在这里已经有了答案: How can I make Java print quotes, like "Hello"? (11 个答案) 关闭 9 年前。 我想在 java 中打印反引号。但是
我认为这是 F# 的一个众所周知的限制,但我找不到任何好的解决方法…… 所以,这里是代码(我试图让它尽可能简单,所以它可能看起来没有任何意义): [] type Human (makeAName: u
我在Windows 7上,在Apache 2.4上使用PHP 5.6.14版:我必须使用PHP在SQLite3数据库上构建查询选择。 NOTA:我是PHP的再见..... 我的代码如下 '; echo
在 jQuery 文档中,大多数字符串都是使用单引号“声明”的。包括documentation用于 jQuery UI。 那为什么不呢 $(".datepicker").datepicker({ da
我正在尝试在 Java 中使用以下正则表达式,它应该与任何 lang="2-char-lang-name" 匹配: String lang = "lang=\"" + L.detectLang(inp
我试图在 more 之后插入一个 block 引用指令,不接受任何参数: First paragraph. .. more:: Blockquote here! -- Author S
我从外部进程获得了一些我无法更改的 JSON,并且我需要修改此 JSON 字符串才能使下游 Java 进程正常工作。 JSON 字符串如下所示: {"widgets":"blah","is_dog":
我试图在从数据库读取数据后生成 CSV 文件。现在单个数据可以包含逗号、单引号和双引号。 请告诉我如何在正则表达式的帮助下处理这种情况。 最佳答案 您可以为 CSV 文件使用不同的分隔符吗?也许是一个
我尝试在 codemodel(Sun) 中创建下一个表达式: driver.findElement(By.xpath("//div[text()=\""+whatToclick+"\"]/pare
我需要知道报价和列表之间的区别。例如: cl-prompt> (equal (first (list * 1 2)) *) T cl-prompt> (equal (first '(* 1 2)) *
我是一名优秀的程序员,十分优秀!