Object scope while attaching an event listener in javascript
<p>I need to do something like this:</p>

<pre><code>for(int i =0; i&lt; results.length; i++){
    $('ul').append('&lt;li&gt;'+results[i].name+'&lt;/li&gt;').bind('click',function(){
        doSomething(results[i]);
    })
}  
</code></pre>

<p>but when the click happens, the object passed to doSomething is undefined. How do I solve this?</p>
