0

I have a Javascript project that must be compatible with older versions of IE, and I am using Eclipse Juno as my IDE.

Older versions of IE cannot handle a comma after the last element of an array, even though this is correct ECMAScript:

[a,b,c,]

Unfortunately, though this is correct syntax, it breaks my application only for IE, and only in production (where backwards compatibility is forced), and in a way that is very hard to debug (it does not fail anywhere near the line that is wrong).

Is there a way to set Eclipse to flag this as an error with the syntax validator? I did not see this as an option under Preferences -> JavaScript -> Validator -> Errors/Warnings

kimon
  • 2,481
  • 2
  • 23
  • 33
  • Note: this is valid as of ES5. IE<8 do not support any ES5 features (in case you're wondering the reason, here's throughout [answer](http://stackoverflow.com/a/7246662/1331430)). – Fabrício Matté Apr 25 '13 at 17:56
  • Is there some good reason to have a trailing comma in an array? If you want to include undefined there, include the keyword. – kennebec Apr 25 '13 at 17:59

1 Answers1

4

I would warmly recommend installing jshint for eclipse which would analyze your code, and provide insightful reports about your code (including the problem you reported)

If you're not sure, just give jshint a try. Paste your code, press lint, and get the results.

Example

For the code:

var arr = [1,2,3,];

You get:

Line 1: var arr = [1,2,3,];

Extra comma. (it breaks older versions of IE)
Matyas
  • 13,473
  • 3
  • 60
  • 73
  • Yes, this worked. Unfortunately it's also flagging a lot of errors for mixed spaces and tabs. It looks like I should be able to tell JSHint to ignore this by setting "smarttabs: true" in the JSHint options, but this does not seem to make any difference... – kimon Apr 25 '13 at 18:43
  • 1
    **Or** you could be consistent about indentation. It only takes you once to (auto)-format it, and then just follow the standards. Jokes aside: I don't know about this bug. – Matyas Apr 25 '13 at 18:47