I am trying to compile my Js code in google closure compiler and I am getting error on this code
var settings = {
providers: ['A', 'B', 'C'],
interface: 'basic16',
apikey: 'XXXXX-XXXXX-XXXXX-XXXXXXXXXX'
}
Errors are
JSC_PARSE_ERROR: Parse error. invalid property id at line 3 character 10
interface: 'basic16',
^
JSC_PARSE_ERROR: Parse error. syntax error at line 3 character 11
interface: 'basic16',
^
JSC_PARSE_ERROR: Parse error. syntax error at line 4 character 8
apikey: 'XXXXX-XXXXX-XXXXX-XXXXXXXXXX'
^
But this code works perfect for me in any browser (chrome, firefox, opera, safari, IE7,8,9)
The MDN states that the keyword
interfaceis reserved for future use and may not be used for property/function/variable names.https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
Thing is, that the MDN also states that the usage of this keyword is only restricted when in strict mode. So I’m not quite sure whether the closure compiler is doing the right thing when it complains about this even in non-strict mode. This looks more like a bug, but it’s probably better to avoid using these keywords anyway.
However, a solution is to simply wrap the identifier in quotation marks: