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

Question on indentation of a var statement

Expand Messages
  • Zhami
    I sometimes do assignments in a var statement. I m not certain whether this is frowned upon. Given that I do, my var statement might contain a mix of mere
    Message 1 of 2 , Jan 23, 2011
    • 0 Attachment
      I sometimes do assignments in a var statement. I'm not certain whether this is frowned upon.

      Given that I do, my var statement might contain a mix of mere declarations and assignments, so I tend to format for visibility, such as in this snippet:

      var d = new Date(),
      ....hours = d.getHours(),
      ....month = d.getMonth() + 1,
      ....day = d.getDate(),
      ....// working variables
      ....d1, d2, h1, h2, m1, m2, s;

      note: the leading periods in each line are to de-mark what is in reality whitespace.

      It seems that once JSLint sees that the declarations are broken up onto separate lines, it wants them all that way (in the above example, all those last "working variables").

      Is my style here considered that objectionable that I should rewrite?
    • Zhami
      ... I just discovered that I can restructure and not get linty messages: var d1, d2, h1, h2, m1, m2, s, ....d = new Date(), ....hours = d.getHours(),
      Message 2 of 2 , Jan 23, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Zhami" <stuart@...> wrote:
        >
        > I sometimes do assignments in a var statement. I'm not certain whether this is frowned upon.
        >
        > Given that I do, my var statement might contain a mix of mere declarations and assignments, so I tend to format for visibility, such as in this snippet:

        <snip>

        I just discovered that I can restructure and not get linty messages:

        var d1, d2, h1, h2, m1, m2, s,
        ....d = new Date(),
        ....hours = d.getHours(),
        ....month = d.getMonth() + 1,
        ....day = d.getDate();
      Your message has been successfully submitted and would be delivered to recipients shortly.