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

1370Re: The Comma Operator Causes JSLint to Stop Prematurely

Expand Messages
  • pauanyu
    Jul 18, 2010
    • 0 Attachment
      I think you are missing the point:

      "It would be nice if JSLint could recognize the Comma Operator and
      display a warning message because the Comma Operator is definately not
      one of Javascript's good parts. Unfortunately, GWT uses them a lot."

      What they are asking is that JSLint output a warning about using the comma operator, NOT that JSLint accept the comma operator as good code.

      In other words, rather than giving vague warnings that aren't specific to the problem, they want JSLint to specifically say "don't use the comma operator".

      --- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...> wrote:
      > You are misusing the comma operator. Commas in JavaScript exist to separate items in a list. Any other use of commas is invalid.
      > Valid uses of commas:
      > var a, b, c = 1, d = 2, e;
      > var myArray = [a, b, c];
      > Your example is invalid, because it is an attempt to assign two single value data types to a single variable. Your example would be valid if you replaced the parenthesis with square brackets as then you would be assigning a list of values to an array. Your example would also be valid if you removed all but one value/variable and all commas. Aside from those two alternatives there is no other way to make your example valid.
      > The logical implication of your example appears to be a tertiary operation, which is assigning an "if" condition to a variable. Here is an example:
      > var a, test = (a) ? 1:5;
      > In that example the variable "a" is tested for an assignment. If "a" is assigned a value "test" receives a value of 1 otherwise "test" receives a value of 5.
      > The JSLint error reporting might possibly be more complicated than necessary considering the simplicity of your example, but it is not wrong.
      > Austin Cheney
      > http://prettydiff.com/
    • Show all 6 messages in this topic