> The comma in its typical uses in variable assignment is pretty useless IMO.
I've screwed myself over a few times by getting into the habit of using the comma in this fashion. If you accidentally make that comma a semicolon, y in your example becomes global. My jQuery plugins all include a default settings object, and they happen to have the same name of "settings". Consequently, default settings for some plugins were being overridden and I had no idea why - until I found that I used a semicolon instead of a comma.
The JavaScript Comma Operator: bringing perl-esque side-effects to your code since....wait, has this thing always been an available operator? Whatever. The JavaScript Comma Operator: bringing perl-esque side effects to your code since it's introduction. There. Ahem.
Given the way js evaluates these, the comma operator seems like it should fit in nicely. I would have made this the first argument in my case for using the comma.
I guess this syntax will now enter my team code-style guideline, as forbidden.
It will nice along the ?: used as a control structure instead of selection.
The comma operator is a bad idea in most cases, but his idea of using it to unobtrusively insert a `console.log` debug statement inside an expression, is pretty clever and might actually be a sort of valid use for this language feature.
Also the way it allows one to formulate a `do { .. } while ( .. )` construction, is a nice and clever trick, but already violating the principle of least astonishment too much.
21 comments
[ 4.1 ms ] story [ 75.9 ms ] threadThat's a curious way to find programmers that are going to write code that you plan to use in production
(though I kinda feel like panning syntax sugar as 'useless' is a little useless. What, are we going to count chars as a scientific comparison?)
http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
I've screwed myself over a few times by getting into the habit of using the comma in this fashion. If you accidentally make that comma a semicolon, y in your example becomes global. My jQuery plugins all include a default settings object, and they happen to have the same name of "settings". Consequently, default settings for some plugins were being overridden and I had no idea why - until I found that I used a semicolon instead of a comma.
It's the same operation as in:
Also the way it allows one to formulate a `do { .. } while ( .. )` construction, is a nice and clever trick, but already violating the principle of least astonishment too much.