The situation is somewhat like-
var someVar = some_other_function();
someObj.addEventListener(\"click\", function(){
some_function(someVar);
}, false);
<
Probably not optimal, but simple enough for those not super js savvy. Put the function that calls addEventListener into its own function. That way any function values passed into it maintain their own scope and you can iterate over that function as much as you want.
Example I worked out with file reading as I needed to capture and render a preview of the image and filename. It took me awhile to avoid asynchronous issues when utilizing a multiple file upload type. I would accidentally see the same 'name' on all renders despite uploading different files.
Originally, all the readFile() function was within the readFiles() function. This caused asynchronous scoping issues.
function readFiles(input) {
if (input.files) {
for(i=0;i