The following code has a bad syntax error. Probably because I'm using 'for' or something.
$.when(
for (var i=0; i < 5; i++) {
$.getScript( "'" + someArr[i].fileName + ".js'");
}
$.Deferred(function( deferred ) {
$( deferred.resolve );
})
).done(function() {
alert("done");
});
I'm trying to call couple of scripts and then when trey are all loaded I want to an alert to show.
If I understand correctly, the code to do what you want can be written concisely with
$.map()
and$.when.apply()
, as follows :Note:
$.when.apply(null, promises)
is equivalent to :where
jqXHR0
etc. arejqXHR
objects returned by five$.getScript()
calls.A commented (but untested) solution with the changes is below
If you have the option, something much simpler is just