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

Function chaining and whitespace issue

Expand Messages
  • mariuszn3
    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
    Message 1 of 5 , Feb 2, 2012
    • 0 Attachment
      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 ?
      Cheers!-- Mariusz
      Nowakhttps://github.com/medikoohttp://twiiter.com/medikoo





      [Non-text portions of this message have been removed]
    • douglascrockford
      ... 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
      Message 2 of 5 , 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);
      • douglascrockford
        Or you can break compactly before ) . var someFunction = function () { use strict ; }; someFunction()(someFunction)(someFunction)(someFunction
        Message 3 of 5 , Feb 2, 2012
        • 0 Attachment
          Or you can break compactly before ')'.

          var someFunction = function () { 'use strict'; };
          someFunction()(someFunction)(someFunction)(someFunction
          )(someFunction)(someFunction);

          The thing you can't do is break between ')' and '(' because of the semicolon insertion hazard.
        • mariuszn3
          Thanks, somehow I didn t think about writing it that way, it indeed makes sense.
          Message 4 of 5 , Feb 2, 2012
          • 0 Attachment
            Thanks, somehow I didn't think about writing it that way, it indeed makes sense.


            --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...> wrote:
            >
            > Or you can break compactly before ')'.
            >
            > var someFunction = function () { 'use strict'; };
            > someFunction()(someFunction)(someFunction)(someFunction
            > )(someFunction)(someFunction);
            >
            > The thing you can't do is break between ')' and '(' because of the semicolon insertion hazard.
            >
          • douglascrockford
            Or you can wrap the whole thing in parens: var someFunction = function () { use strict ; }; (someFunction() (someFunction) (someFunction) (someFunction)
            Message 5 of 5 , Feb 10, 2012
            • 0 Attachment
              Or you can wrap the whole thing in parens:

              var someFunction = function () { 'use strict'; };
              (someFunction()
              (someFunction)
              (someFunction)
              (someFunction)
              (someFunction)
              (someFunction));
            Your message has been successfully submitted and would be delivered to recipients shortly.