Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript keywords in hash keys

In V8-based JS engines, you can use unquoted keywords in property keys, like ({ delete: 1 }), while in Rhino or other JS engines, 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 }
like image 767
Ming-Tang Avatar asked Nov 28 '10 19:11

Ming-Tang


1 Answers

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.

like image 84
Daniel Vassallo Avatar answered Oct 02 '22 21:10

Daniel Vassallo