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

Re: [jslint] Re: Switch Case Style

Expand Messages
  • Felix E. Klee
    On Sat, Feb 2, 2013 at 4:33 PM, paperlampshade ... Looks strange. The following formatting is IMHO easy to read and it is accepted by
    Message 1 of 6 , Feb 2 8:35 AM
    • 0 Attachment
      On Sat, Feb 2, 2013 at 4:33 PM, paperlampshade <beefo@...>
      wrote:
      > ~~~~switch (input) { case 1:
      >
      > [...]
      >
      > Why is it important to have switch case syntax as in the second example?

      Looks strange. The following formatting is IMHO easy to read and it
      is accepted by JSLint:

      var test = function (input) {
      'use strict';
      var output;
      switch (input) {
      case 1:
      output = "a";
      break;
      case 2:
      output = "b";
      break;
      case 3:
      output = "c";
      break;
      default:
      output = "";
      }
      return output;
      };

      BTW, just post emails in plain-text and no need to insert these ugly
      `~`.
    • douglascrockford
      ... Thanks. Please try it now.
      Message 2 of 6 , Feb 2 10:03 AM
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "paperlampshade" wrote:
        >
        > Hi,
        > I have a question about Switch Case style as verified in jslint.A switch
        > case written as below (case statement starting on the line after the
        > switch statement) will give many errors regarding the expected position
        > from line "case 1:" to line "output = "";".
        > var test = function (input) { 'use strict'; var output; switch
        > (input) { case 1: output = "a"; break;
        > case 2: output = "b"; break; case 3:
        > output = "c"; break; default: output = "";
        > } return output;};
        > However when the same statement is written with the "case 1:" statement
        > beginning one space after the switch "{" and the closing "}" one space
        > from the "output = "";" line, there is no errors found.Example below:
        > var test = function (input) { 'use strict'; var output; switch
        > (input) { case 1: output = "a"; break; case
        > 2: output = "b"; break; case 3:
        > output = "c"; break; default: output = "";
        > } return output;};
        > Why is it important to have switch case syntax as in the second example?


        Thanks. Please try it now.
      • paperlampshade
        Works great! Thanks very much.
        Message 3 of 6 , Feb 4 7:36 PM
        • 0 Attachment
          Works great! Thanks very much.

          --- In jslint_com@yahoogroups.com, "douglascrockford" wrote:
          >
          > --- In jslint_com@yahoogroups.com, "paperlampshade" wrote:
          > >
          > > Hi,
          > > I have a question about Switch Case style as verified in jslint.A switch
          > > case written as below (case statement starting on the line after the
          > > switch statement) will give many errors regarding the expected position
          > > from line "case 1:" to line "output = "";".
          > > var test = function (input) { 'use strict'; var output; switch
          > > (input) { case 1: output = "a"; break;
          > > case 2: output = "b"; break; case 3:
          > > output = "c"; break; default: output = "";
          > > } return output;};
          > > However when the same statement is written with the "case 1:" statement
          > > beginning one space after the switch "{" and the closing "}" one space
          > > from the "output = "";" line, there is no errors found.Example below:
          > > var test = function (input) { 'use strict'; var output; switch
          > > (input) { case 1: output = "a"; break; case
          > > 2: output = "b"; break; case 3:
          > > output = "c"; break; default: output = "";
          > > } return output;};
          > > Why is it important to have switch case syntax as in the second example?
          >
          >
          > Thanks. Please try it now.
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.