$.get()
returns a Deferred object. In this line, you creating an array full of Deferred instances, one for each request you have happening:
dfdArr.push($.get("get_test_" + i + ".php"));
$.when()
accepts a list of Deferred objects and returns its own Deferred. When all of the Deferred objects you gave it are resolved, it resolves too. Normally this is something like:
$.when(dfd1, dfd2).done(function (dfd1Result, dfd2Result) {
// The parameters from dfd1.done and dfd2.done are here in dfd1REsult, dfd2Result
}
We don't want to use a list, we want to use an array. That's where .apply()
comes in. This allows you to use an array of deferreds.
Now, our callback function doesn't know how many results it will have, so it doesn't make sense to explicitly list them. We essentially get an array of results by looking at the arguments
array, which is present in any function.