1370Re: The Comma Operator Causes JSLint to Stop Prematurely
- Jul 18, 2010I 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
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 firstname.lastname@example.org, "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...> wrote:
> 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
- << Previous post in topic Next post in topic >>