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

Line Breaking Error

Expand Messages
  • Jacob Davenport
    This produces an error: function a() { return ( doStuff(m, n) + someString ); } Imagine that the doStuff and someString lines are long, thus the desire to
    Message 1 of 2 , Aug 15, 2008
    View Source
    • 0 Attachment
      This produces an error:

      function a() {
      return (
      doStuff(m, n) +
      "someString"
      );
      }

      Imagine that the doStuff and someString lines are long, thus the
      desire to break them up over several lines. However, this does not
      produce an error:

      function a() {
      return (
      "someString" +
      doStuff(m, n)
      );
      }

      Is the first one actually dangerous in some way that the second one is
      not? Is JavaScript going to stick a semicolon after "someString"
      unless it is followed by a plus sign, but not after the doStuff
      function call?

      Both seem to work in IE6, IE7, and FF.

      Thanks again for this great tool.
    • Douglas Crockford
      ... JSLint does not like to break after a string literal. This is protect you from semicolon insertion. You can either turn on the sloppy line breaking option,
      Message 2 of 2 , Aug 15, 2008
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Jacob Davenport" <jacob@...> wrote:
        >
        > This produces an error:
        >
        > function a() {
        > return (
        > doStuff(m, n) +
        > "someString"
        > );
        > }

        JSLint does not like to break after a string literal. This is protect
        you from semicolon insertion. You can either turn on the sloppy line
        breaking option, or you can break you statement differently. For example,

        function a() {
        return doStuff(m, n) +
        "someString";
        }
      Your message has been successfully submitted and would be delivered to recipients shortly.