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

Re: [jslint] Problems with default and switch (UNCLASSIFIED)

Expand Messages
  • Cheney, Edward A SSG RES USAR USARC
    Classification: UNCLASSIFIED Luke, JSLint does not like fall through on case statements. The examples where JSLint is not throwing an error is because you
    Message 1 of 2 , Jan 11, 2011
    • 0 Attachment
      Classification: UNCLASSIFIED
      Luke,

      JSLint does not like fall through on case statements. The examples where JSLint is not throwing an error is because you have provided an escape condition. To make JSLint happy and your code less error prone do one of these:

      1) Don't use switch/case
      2) Insert a break statement at the end of empty case statements

      Honestly, I try to avoid using switch/case in my own code. It is less flexible than a complex list of "else if" conditions and its performance benefit is negligible compared to well written conditions. The only benefit is for the programmer to type less characters when writing code, which is not really a qualitative benefit.

      Austin Cheney, CISSP
      http://prettydiff.com/
      Classification: UNCLASSIFIED
    • Luke Page
      In creating a simple case I completely missed that I can remove the this.b: case as it will fall through to the default block. I ve added a comment for clarity
      Message 2 of 2 , Jan 11, 2011
      • 0 Attachment
        In creating a simple case I completely missed that I can remove the this.b:
        case as it will fall through to the default block. I've added a comment for
        clarity instead of the case.

        Sorry for falling in to the trap of thinking a new error in existing code
        must mean JSLint is inconsistent about something.

        re: Switches - I use them for switching on enumerations and think they look
        far clearer in terms of letting another programmer quickly see what you are
        achieving.

        On 11 January 2011 11:26, Cheney, Edward A SSG RES USAR USARC <
        austin.cheney@...> wrote:

        >
        >
        > Classification: UNCLASSIFIED
        > Luke,
        >
        > JSLint does not like fall through on case statements. The examples where
        > JSLint is not throwing an error is because you have provided an escape
        > condition. To make JSLint happy and your code less error prone do one of
        > these:
        >
        > 1) Don't use switch/case
        > 2) Insert a break statement at the end of empty case statements
        >
        > Honestly, I try to avoid using switch/case in my own code. It is less
        > flexible than a complex list of "else if" conditions and its performance
        > benefit is negligible compared to well written conditions. The only benefit
        > is for the programmer to type less characters when writing code, which is
        > not really a qualitative benefit.
        >
        > Austin Cheney, CISSP
        > http://prettydiff.com/
        > Classification: UNCLASSIFIED
        >
        >


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.