You want to rely on a comma, because if you rely on a design with several assignments, you will shoot in the leg at some point.
Example:
>>> var a = b = c = []; >>> c.push(1) [1] >>> a [1]
They all refer to the same object in memory, they are not "unique", because at any time you make a reference to the object (array, object literal, function), which it passed by reference, and not by value. Therefore, if you change only one of these variables and want them to act individually, you will not get what you want, because these are not separate objects.
There is also a drawback to multiple assignments, as secondary variables become global and you donβt want to seep into the global namespace.
(function() { var a = global = 5 })(); alert(window.global)
It is best to use commas and preferably with a lot of spaces so that it reads:
var a = 5 , b = 2 , c = 3 , d = {} , e = [];
meder omuraliev Nov 12 '10 at 16:27 2010-11-12 16:27
source share