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

1724Re: [jslint] Error Suggestion

Expand Messages
  • Erik Eckhardt
    Jan 4, 2011
    • 0 Attachment
      Most certainly a mistake, since a function invocation requires the opening
      parenthesis right after the function name.

      So even if the function returned a function which was immediately executed,
      putting it on the next line would be a mistake. I for one vote for your
      suggestion to flag the line breaking you suggested as invalid.

      function fnReturningFn() {
      return function() {alert('Hello World!');};
      }

      fnReturningFn()(); // not sure if this is valid, but why not?

      fnReturningFn()
      ___(); // I'm sure this isn't right

      On Tue, Jan 4, 2011 at 11:14 AM, Luke Page <luke.a.page@...> wrote:

      >
      >
      > yes and I don't think that should be stopped, but would it make sense to
      > have
      >
      >
      > $('#id').appendChild
      > (div).css
      > ('background-color', 'blue').show();
      >
      > I think that would always be a mistake?
      >
      >
      > On 4 January 2011 18:37, Erik Eckhardt <erik@...<erik%40eckhardts.com>>
      > wrote:
      >
      > > In popular javascript libraries like jQuery that use chaining, line
      > breaks
      > > are common:
      > >
      > > $('#id').appendChild(div)
      > > ___.css('background-color', 'blue')
      > > ___.show();
      > >
      > > On Tue, Jan 4, 2011 at 5:50 AM, Luke Page <luke.a.page@...<luke.a.page%40gmail.com>>
      > wrote:
      > >
      > > >
      > > >
      > > > Can I suggest there should not be allowed to be a line break between a
      > > > function and invoking it?
      > > >
      > > > I had something like the following code
      > > >
      > > > var a = b && (c || d)
      > > > (e || f).push(g);
      > > >
      > > > where I had mistakenly missed a semi-colon and it was not picked up by
      > > > JSLint.
      > > >
      > > > it causes an error because the result of "b && (c || d)" is a boolean
      > and
      > > > it
      > > > is being run as a function.
      > > >
      > > > Would it ever be valid (or good practice) to have a newline before a
      > > > function execution or is there some other way to pick this up in
      > JSLint?
      > > >
      >


      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic