I am scrambling to fix a production error and am not a JS developer. Before my analysis can go any further I need to be absolutely confident that I am making some correct assumptions about the following line of code:
var iVO = {
"images":{}
};
var thisImage = $(this).data("data");
iVO["images"][thisImage.fileKey] = thisImage;
iVO["images"][thisImage.imageType] = imageType;
iVO["images"][thisImage.uploadReason] = uploadReason;
Here are my assumptions. If any are correct or misguided, please correct me:
iVOis an array of JSON objects- Each of these JSON objects is then given 3 properties (
fileKey,imageTypeanduploadReason)
The thing that I don’t get is the significance of the "images" index, What is the value/meaning of iVO["images"]? What does information/objects this first/outer array represent?
iVOis an object literal. It functions like a hash.iVO["images"]looks like array access, but in this case the code is accessing theimagesproperty oniVO. In the end, it returns whatimagespoints at, which is{}, another object literal.var thisImage = $(this).data("data")is using a jquery function. The documentation for jQuery.data is here.thisImageis a reference to the data returned from the invocation ofdataiVO["images"][thisImage.fileKey] = thisImage;is just setting a value. The first access is accessing the
imagesproperty oniVO, which was a an object literal. From that object literal, the code assigns the propertythisImage.fileKey(whatever that is, it comes out of the data call on the previous line) the value ofthisImage.So, when you say
iVOis a single object literal, that contains another object literal under theimagesproperty.That object literal has 3 values stuffed in it. The keys (the named of the properties) depends on what the
datacall returned. The values depend onthisImage(the result of the data call), and the variablesimageType, anduploadReason.You can use your debugger to step thru this code and see what the values are at each step.
Note JSON is not coming into play here. From json.org, “JSON is a text format that is completely language independent….”