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

1452Re: [jslint] dot property name

Expand Messages
  • Rob Richardson
    Aug 25, 2010
      I prefer to indent long chains by putting the dot at the beginning of the
      next line like so:

      var bar = foo
      .replace('o', '0')
      .click(function () {
      $(this).hide();
      };

      In this way it's clear to me by scanning the far left edge of my code that
      "replace" and "click" aren't under-declared vars.

      Rob


      On Wed, Aug 25, 2010 at 3:55 PM, Mark Volkmann <r.mark.volkmann@...>wrote:

      >
      >
      > On Wed, Aug 25, 2010 at 5:44 PM, Marcel Duran <contact@...<contact%40marcelduran.com>>
      > wrote:
      > > Couldn't it be optional?
      > >
      > > I believe this is useful when indenting long chain of methods like some
      > > popular JS frameworks do.
      > >
      > > The following although correct wouldn't be OK to JSLint:
      > > function func1(foo) {
      > > var bar = foo.
      > > replace('o', '0').
      > > replace('a', '4');
      > > return bar;
      > > }
      >
      > This is how I indent long chains of method calls.
      >
      >
      > > A possible workaround would be:
      > > function func2(foo) {
      > > var bar = foo.replace(
      > > 'o', '0'
      > > ).replace(
      > > 'a', '4'
      > > );
      > > return bar;
      > > }
      > >
      > > Not sure how developers are indenting long chains, specially jQuery ones.
      > >
      > > Marcel
      > >
      > >
      > > On Wed, Aug 25, 2010 at 3:17 PM, Douglas Crockford <
      > douglas@... <douglas%40crockford.com>>wrote:
      > >
      > >>
      > >>
      > >> JSLint now requires that there be no whitespace or line break between a
      > .
      > >> and a property name. This has always been a good practice, and is now
      > >> especially desirable because of reserved word relaxation in ES5.
      > > --
      > > Marcel Duran
      >
      > --
      > R. Mark Volkmann
      > Object Computing, Inc.
      >


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