Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google closure compiler Javascript parse error

I am trying to use google closure compiler on my javascript files. It works fine except for the following piece of code:

function goto(form) { var index=form.select.selectedIndex
if (form.select.options[index].value != "0") {
location=form.select.options[index].value;}}

The compiler returns:

JSC_PARSE_ERROR: Parse error. missing ( before function parameters. at line 1 character 9 function goto(form) { var index=form.select.selectedIndex

There is a caret (^) pointing to the g in "goto" when it is output on the screen.

I am using just the basic UI version here to test:

http://closure-compiler.appspot.com/home

Any idea what is wrong with the javacript? It seems to work just fine but I am not a javascript person so I have no clue how to fix it.

like image 209
William Smith Avatar asked Aug 01 '26 23:08

William Smith


1 Answers

I am not sure why @Sirko deleted his answer. So I will add it.

You need to change the name of the function goto to something else. Something like gotoUrl, gotoPage, etc.

It was a reserved word in ECMAScript 3, but removed in ECMAScript 5. I am guessing the closure compiler uses that older list still.

like image 103
epascarello Avatar answered Aug 03 '26 13:08

epascarello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!