JSFiddle - React, Tailwind, and code Playground
JavaScript
var a=[],b=[],i;
// define the functions
for(i=0;i<3;i++){
a[i]=(function(i){return function(){b[i]=i;}})(i);
}
// if this works properly, array b will be [0,1,2]
// once all the functions in array a have been called
// call the functions (simulating an image.onload)
for(i=0;i<3;i++)a[i]();
// display the result
alert(b.join());