What are the dangers of breaking a line of long code up at a close parenthesis?
When could a semicolon be automatically inserted by Javascript (pres
This link should explain it all:
JavaScript Semicolon Insertion
The "danger" is with (taken from the above link, emphasis added):
There are five restricted productions in the grammar, they are the postfix operators ++ and --, continue statements, break statements, return statements, and throw statements.
function()
is not in that "danger" list. However, when writing semi-colon free-code (I'm not sure if this is your aim :-), one should guard against lines starting with characters -- such as (
or [
-- that may start or continue an expression. The following code shows an example of code which is likely wrong:
x()
(function (){...})()
As you can see, using )
as a line-breaker may make the expression able to continue on subtly without an explicit semi-colon iff the next line can continue the expression. I write the proceeding as (if the following is indeed the intent):
x()
;(function (){...})()
Personally, I dislike JSLint :-) Happy coding.