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 (presumably that is the danger, right?).
Why is using a
)
as a line breaker "frowned upon" by JSLint?
In Javascript I sometimes see one long line of code broken up at a )
like this (example):
function ()
{
or like this (example):
object.methodOne()
.methodTwo();
But when reading the line break expectations for jsLint, it says:
As a further defense against the semicolon insertion mechanism, JSLint expects long statements to be broken only after one of these punctuation characters or operators:
, ; : { } ( [ = < > ? ! + - * / % ~ ^ | &
== != <= >= += -= *= /= %= ^= |= &= << >> || &&
=== !== <<= >>= >>> >>>=
JSLint does not expect to see a long statement broken after an identifier, a string, a number, closer, or a suffix operator:
. ) ] ++ --
So the close parenthesis is singled out as a line breaker that JSLint "doesn't expect to see."
I would prefer to use
function()
{
since I find it more readable, and I already use it in other languages, but currently I use:
function () {
Could I safely use the )
to break up long lines?