Re:Ask HN: Why use semicolons to terminate statements in mod...
by timknauf on Tuesday November 25, 2008 @01:06AM
(#376075)
Interesting. I've encountered errors in a similar vein, which in retrospect must have been caused by using an anonymous list in a similar way to your example:
[f1, f2][intIndex]()
The 'solution' seems to be something like var functions = [f1, f2]
functions[intIndex]()
but that's a big loss for conciseness.
The problem is, the javascript rules for continuing lines are that whenever the next character is any of [({+-, the line is assumed to continue. This is generally correct but not always. For comparison, the analogous Python rule is that a line continues either with an explicit \ or when one of [({ has not yet been closed with its pair. The Python rule doesn't lead to any ambiguous cases that I am aware of, because unclosed parentheses would just be invalid syntax.