title: jQuery variable capture in loop
body: <p>My understanding of JS and jQuery is pretty limited, and I come from a C# background. But I do know what variable capture is, and I know that if I capture a variable inside the loop that was declared OUTSIDE of a loop, each time the delegate runs I'll get the last value of the captured variable, not the one at the time of the capture.
  However, this is clearly not the issue here, yet <strong>I still receive the last value</strong>:</p>
  
  <pre><code>for (var i = 0; i &lt; dialogs.length; i++) {
  
      var dialog_button = dialogs[i];
  
      var ix_parts = $(dialog_button).attr("id").split("_");
      var index_tag = ix_parts[1];
      var dialog_panel = $(dialog_panel_selector.replace("$ix$", index_tag));
       $(dialog_button).click(function (event) {
              $(dialog_panel).dialog('open');
              return false;
          });
  </code></pre>
  
  <p>}</p>
  
  <p>Since dialog_button was declared inside the loop's scope, I'd expect that I'll receive the correct value inside the click handler.<br>
  <em>Is JS doing something different?</em></p>