Today, mastering JS, I noticed this piece of code:
reader.onload = (function(theFile) { return function(e) { // Render thumbnail. var span = document.createElement('span'); span.innerHTML = ['<img class="thumb" title="', escape(theFile.name), '" src="', e.target.result, '" />'].join(''); document.getElementById('output').insertBefore(span, null); }; })(f); Specifically, I was interested in the last line, where, after the parameters of the .onload function, the variable is passed in separate brackets. Please explain why it is needed and how it works, because without it the script is not executed.