开发者

JavaScript keywords in hash keys

开发者 https://www.devze.com 2023-01-28 09:28 出处:网络
In V8-based JS engines, you can use unquoted keywords in property keys, like ({ delete: 1 }), while in Rhino or other JS e开发者_StackOverflow社区ngines, it throws an error, how is that possible? What

In V8-based JS engines, you can use unquoted keywords in property keys, like ({ delete: 1 }), while in Rhino or other JS e开发者_StackOverflow社区ngines, it throws an error, how is that possible? What should be the correct behavior?

spaceman@spaceman-laptop:~$ rhino
Rhino 1.7 release 2 2010 01 20
js> ({ delete: 1 })        
js: "<stdin>", line 2: invalid property id
js: ({ delete: 1 })
js: .........^
js> 
spaceman@spaceman-laptop:~$ node
> ({ delete: 1})
{ delete: 1 }


The new ECMAScript 5 specification allows property names to be reserved words. Some engines might have adopted this new "feature", while others might still require property names to be quoted when they happen to be reserved words.


For sake of clarity you might want to avoid delete or new or other operators as property names, even while newer specs is relaxed about it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号