Chrome中带有({})的默认令牌意外默认值 [英] Unexpected token default in Chrome with ({}).default
问题描述
我在Chrome(+ Opera)中的任何对象上获取或设置属性default时收到错误SyntaxError:Unexpected token default
。
I receive error "SyntaxError: Unexpected token default" while getting or setting attribute "default" on any object in Chrome (+Opera).
({}).default
有人可以解释为什么会发生这种情况?
Can someone explain why this happens ?
upd:每个人,PLZ,因为它对FF没有意义所以在测试时你可以错过这个bug。
upd: everybody, plz, becareful it doesn't make sense for FF so while testing you can miss this bug.
推荐答案
默认
是JavaScript中的关键字(对于切换
语句)。
default
is a keyword in JavaScript (for the switch
statement).
在ECMAScript第五版中允许使用点属性访问器中的保留字(具体来说:点属性访问器的语法是 MemberExpression。IdentifierName
[section 12.2.1]和 IdentifierName
,与 Identifier $不同c $ c>,可能是
ReservedWord
[第7.6节]),但不在ECMAScript第三版中(其中 MemberExpression。标识符
)。第三版目前是所有浏览器支持的基准。
Using reserved words in dot property accessors is allowed in ECMAScript Fifth Edition (specifically: the syntax for the dot property accessor is MemberExpression . IdentifierName
[section 12.2.1], and IdentifierName
, unlike Identifier
, may be a ReservedWord
[section 7.6]), but not in ECMAScript Third Edition (where it's MemberExpression . Identifier
). Third Edition is currently the baseline all browsers support.
为安全起见, []
属性访问:
For safety use []
property access:
({})['default']= ...;
或避免使用关键字作为属性名称。
or avoid using keywords as property names.
这篇关于Chrome中带有({})的默认令牌意外默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!