Why does this outputs some weird thing?
And what do parenthesis around (function(i) { onImageLoad(i); })
do? It seems like they "materialize" the function but I would like to know the real term.
function startGame() {
for (var i = 0; i < assets.length; i++) {
frames.push(new Image());
// correct
//frames[i].onload = (function(i) { onImageLoad(i); })(i);
// wrong
frames[i].onload = function(i) { onImageLoad(i); };
frames[i].src = assets[i];
}
setInterval(animate, frameRate);
}
onImageLoad = function(n) {
console.log("image number", n, "loaded");
}
image number Event {clipboardData: undefined, cancelBubble: false, returnValue: true, srcElement: img, defaultPrevented: false…} loaded