4 ms·
The comma in its typical uses in variable assignment is pretty useless IMO. var x = 1, y = 2; Destructuring lists would be a much more useful appl
by zephjc 15y ago
The comma in its typical uses in variable assignment is pretty useless IMO.
var x = 1,
y = 2;
Destructuring lists would be a much more useful application
var x, y = [1, 2];
or
var tmp = [1, 2]
...
var x, y = tmp;
would be far more useful.
- tmcw 15y agoWell, lucky for you in Javascript 1.7: https://developer.mozilla.org/en/New_in_JavaScript_1.7#Destructuring_assignment_(Merge_into_own_page.2Fsection) https://developer.mozilla.org/en/New_in_JavaScript_1.7#Destr... (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?)
- magicalist 15y agoeven more excitingly, destructuring has been moved into the draft ECMAScript 6 spec: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
- RegEx 15y ago> 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.