10

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 }
Ming-Tang
  • 17,410
  • 8
  • 38
  • 76

2 Answers2

15

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.

Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
  • 1
    I found the difference: http://www.google.com/codesearch/p?hl=en#W9JxUuHYyMg/trunk/src/parser.cc&q=parser%20package:http://v8%5C.googlecode%5C.com&l=3914 and http://mxr.mozilla.org/js/source/js/rhino/src/org/mozilla/javascript/Parser.java#3083 the V8 explicitly accepted keyword tokens – Ming-Tang Nov 28 '10 at 20:59
  • 1
    Note that (at least) all browser engines are moving to the ES5 behaviour of allowing property names to be reserved words. – gsnedders Nov 29 '10 at 04:28
2

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

Free Consulting
  • 4,300
  • 1
  • 29
  • 50