How to reference right value of `i` in a callback in a loop?
<p>I have this code :</p>

<pre><code>for (var i = 0; i &lt; result.length; i++) {
    // call a function that open a new "thread"
    myObject.geocode({ param1: "param" }, function(results, status) {
        alert(result.title[i]);
    });                                             
}
</code></pre>

<p>The <code>.geocode</code> function (that is not mine, so I can't edit) open a new "thread" of execution. </p>

<p>When I try to print title on each step, I get always the last possible value of <code>i</code>.</p>

<p>How can I keep a reference to the right value of <code>i</code> for each iteration?</p>
