Re: JSLint does not allow commas inside of arrays
- --- In email@example.com, "pauanyu" <pcxunlimited@...> wrote:
>JSLint will now continue after an extra comma in an array literal.
> --- In firstname.lastname@example.org, "douglascrockford" <douglas@> wrote:
> > This is a hazard. It is indistinguishable from the accidental inclusion of an extra comma, which is a common typo. It also encourages the development of tricky positional array structures when an object would serve better.
> > So I recommend that you explicitly include values between those commas.
> Fair enough. What bothers me far more is that it stops the test! So if there's any errors after the bad commas, you won't get to see them. I'm okay with it throwing an error, but does it really need to completely halt any further processing?
But I still recommend that you fix your code.
- --- In email@example.com, "douglascrockford" <douglas@...> wrote:
> JSLint will now continue after an extra comma in an array literal.
> But I still recommend that you fix your code.
Actually, I would never write such garrish code (normally). Allow me to explain my use case (and how I found out about this):
I have a function that converts a string into an array. For instance, the string "[0, 1, 2, 3, 4]" gets converted into the array [0, 1, 2, 3, 4].
It needs to be able to handle a variety of situations; strings, booleans, numbers, etc. So I wrote a bunch of unit tests to verify that it is working properly. They have already helped me catch a couple regressions.
The goal of the function was to convert the string as accurately as possible, so if you pass in the string "[,,,]" you should get back the array [,,,]. I had a unit test that verified that commas in the string would properly get converted to commas in the array.
When running these unit tests in JSLint, I stumbled upon the error, hence this post.
- --- In firstname.lastname@example.org, Paul Novitski <paul@...> wrote:
>You are quite right. I meant to say "There are times where you wish to leave the value of particular indices of an array as undefined."
> I imagine this was just a typo but just in case it wasn't I'll point
> out that it's not the indices here that are undefined, it's the
> values. The indices for the array above are consecutive integers 0-6.
> Paul Novitski
> Juniper Webcraft Ltd.