Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "Bad Line Breaking" obsolete with "use strict"?

Please assume 'use strict'; and also assume that, JSLint is on and errors cannot be ignored.

I find operators and ',' initiated lists so much more readable,

e.g.:

var i = 0
    , j = 1
    , someLongVariablename1
    , someLongVariablename2
    , someLongVariablename3
    , someLongVariablename4;

 if( (
     'dcr' === cmd
      && (action)
      && ('get' === actionHttp || 'post' === actionHttp )
      && whatever
   ) { ... }

Hence my question:
Is "Bad Line Breaking" obsolete with "use strict"?

EDITED: 'use strict'; will not prevent the execution of bad line breaking the code. It can prevent the execution of some kinds of errors.

I see that JSLint and JSHint treat bad line breaking differently. JSHint is much friendlier towards the syntax I prefer.

So that, may be a solution for others who are working on this.

like image 785
Ron Wertlen Avatar asked Feb 18 '13 08:02

Ron Wertlen


Video Answer


1 Answers

Unfortunately, strict mode doesn't disable the horror that is automatic semicolon insertion, and so "bad" line breaks remain an issue. For example:

(function() {
  "use strict";

  console.log(foo());

  function foo() {
    var a = 1, b = 2;

    return
    a + b;
  }
})();

Live Example | Source (you need to open the console and look at it)

That still logs undefined rather than 3, because ASI kicks in and adds a semicolon after the return in foo.

like image 197
T.J. Crowder Avatar answered Oct 08 '22 04:10

T.J. Crowder