title: JS add event handler using for loop, passing self as parameter not working
body: <p>I am wondering why the statement &quot;let im = _imgs[i];&quot; is indispensable in this situation.
  Essentially, the _imgs are an array of image elements. But if I add the eventhandlers by <code>_imgs[i].addEventListener(&quot;click&quot;, function(){clickImage(_imgs[i]);}, false);</code>, it won't work.</p>
  <p>Can anyone explain why? Thanks a lot!</p>
  <pre><code>function init()
  {
      _imgs = document.querySelectorAll(&quot;#block2 img&quot;);
      console.log(_imgs.length);
      _clicked = new Object();
      for(var i = 0; i &lt; _imgs.length; i++)    
      {      
          let im = _imgs[i];
          _imgs[i].addEventListener(&quot;click&quot;, function(){clickImage(im);}, false);
          _clicked[_imgs[i].id] = 0;
      }
      console.log(&quot;hi&quot;);
  }
  </code></pre>