title: Access outside variable in loop from Javascript closure
body: <p>See:</p>
  
  <pre><code>for (var i in this.items) {
      var item = this.items[i];
      $("#showcasenav").append("&lt;li id=\"showcasebutton_"+item.id+"\"&gt;&lt;img src=\"/images/showcase/icon-"+item.id+".png\" /&gt;&lt;/li&gt;");
      $("#showcasebutton_"+item.id).click(function() {
          alert(item.id);
          self.switchto(item.id);
      });
  }
  </code></pre>
  
  <p>The problem is that the alerted item.id is always the id of the last item in the array (this.items). How to solve?</p>