Problems with the Closure compiler with an object

I am trying to compile Js code in google compiler and I am getting error in this code

var settings = { providers: ['A', 'B', 'C'], interface: 'basic16', apikey: 'XXXXX-XXXXX-XXXXX-XXXXXXXXXX' } 

Mistakes

 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 is great for me in any browser (chrome, firefox, opera, safari, IE7,8,9)

+4
source share
2 answers

The MDN states that the interface keyword is reserved for future use and cannot be used for property / function / variable names.

https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words

The fact is that MDN also states that the use of this keyword is restricted to strict mode only. So I'm not quite sure if the compiler does the closure correctly when it complains about it even in lax mode. This sounds more like an error, but it's probably best to avoid using these keywords.

However, the solution is to simply wrap the identifier in quotation marks:

 var settings = { providers: ['A', 'B', 'C'], 'interface': 'basic16', apikey: 'XXXXX-XXXXX-XXXXX-XXXXXXXXXX' }; 
+7
source

Exmanscript 3 forbade keywords and reserved keywords as property names. Action 5 removed this restriction (they are still forbidden as variable and function names). However, the compiler uses ecmascript 3 by default.

+3
source

All Articles