How to avoid reference to last index in a for loop while sending index as parameter for a function?
<p>I have written this code: </p>

<pre><code>function(targetSliderObject, images){
        // create thumbs container
        var thumbsContainer = $("&lt;div&gt;&lt;/div&gt;").addClass(defaultOptions.thumbsContainerClass);
        // add thumbs
        for(i in images)
        {
            thumb = $("&lt;img /&gt;").addClass(defaultOptions.thumbItemClass).addClass(i);
            thumb.attr("src", images[i]);
            thumb.click(function(){
                methods.slideNext(targetSliderObject, i);
            });
            thumb.appendTo(thumbsContainer);
        }
        // add thumbs container to container
        targetSliderObject.append(thumbsContainer);
}
</code></pre>

<p>What I intend to do is calling method.slideNext() with a different number each time, but insted I get to send a reference to i as parameter for the function which, in the end, is the last index of my array for all my thumbs.</p>

<p>What trick can I use to accomplish what I want ?</p>

<p>Thank you!</p>
