title: Attaching onchange function event to variable
body: <p>I recently got into closures and anonymous functions, and I'm wondering if my code is the right way to do it (it works!):</p>
  
  <pre><code>newInput.onchange = function(x){
       return function(){
            PassFileName(x);  
       }
  }(counter);
  </code></pre>
  
  <p>so this is in a loop that "saves" the current 'counter' value (1,2,3...). If I didn't have the return function, then 'counter' will always be the last value of 'counter'.</p>
  
  <p>Am I approaching this correctly with that code? or is there a better way to "capture" the current counter and attach it to an onchange event?</p>
  
  <p>thank you!</p>