Loading ...
Sorry, an error occurred while loading the content.

2775Re: Function chaining and whitespace issue

Expand Messages
  • douglascrockford
    Feb 2, 2012
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "mariuszn3" <medikoo.yahxo.com@...> wrote:
      >
      > Hi,
      > I approached a whitespace issue. I have a code that it's impossible to
      > refactor so it's ok for jslint - I can resign from checking whitespace
      > but I don't want to do that.Generic example:
      > var someFunction = function () { 'use strict'; };
      > someFunction()(someFunction)(someFunction)(someFunction)(someFunction)(s\
      > omeFunction);
      > This shows: Problem at line 3 character 85: Line too long. Let's move
      > then part of the code to new line:
      > var someFunction = function () { 'use strict'; };
      > someFunction()(someFunction)(someFunction)(someFunction)(someFunction)(s\
      > omeFunction);
      > Now we have: Problem at line 4 character 1: Expected '(' at column 5,
      > not column 1. and Problem at line 4 character 1: Unexpected space
      > between ')' and '('.
      > If I indent second line as first message suggests:
      > var someFunction = function () { 'use strict'; };
      > someFunction()(someFunction)(someFunction)
      > (someFunction)(someFunction)(someFunction);
      > Still I got: Problem at line 4 character 5: Unexpected space between ')'
      > and '('. so it turns out it's impossible to make that code valid.
      > In my opinion following should be valid:
      > var someFunction = function () { 'use strict'; };
      > someFunction()(someFunction)(someFunction)(someFunction)(someFunction)(s\
      > omeFunction);
      > Is there anything that can be done about that ?

      You may be going overboard on the function chaining thing.

      When you break a line after '(', JSLint expects to see an open configuration. So


      var someFunction = function () { 'use strict'; };
      someFunction()(someFunction)(someFunction)(
      someFunction
      )(someFunction)(someFunction);
    • Show all 5 messages in this topic