I understand that the expression in parentheses in Javascript returns the result of evaluating the expression in parentheses:
x = ( 1, 2, 3 );
will evaluate the three above expressions and return the result of the latter: '3', as mentioned in some other posts.
The following code sample from SlickGrid contains what I'm not quite sure I understand:
$(function () { for (var i = 0; i < 500; i++) { var d = (data[i] = {}); d["title"] = "Record " + i; d["n1"] = Math.round(Math.random() * 10); d["n2"] = Math.round(Math.random() * 10); d["n3"] = Math.round(Math.random() * 10); d["n4"] = Math.round(Math.random() * 10); d["n5"] = Math.round(Math.random() * 10); } grid = new Slick.Grid("#myGrid", data, columns, options); })
In particular, the expression:
var d = (data[i] = {});
seems to return a reference to the associative array initialized in the expression in parentheses.
Is this really what is going on? Is there a more detailed explanation for this? Is there a reason to do this instead of something more obvious, such as creating an associative array 'd' and then setting it to 'data [i]'?
source share