Javascript pass values to function on event listener
<p>If I do the following the variable is passed to the attached event listener where as I want the value of the variable at the time the event listener is added passed.</p>

<pre><code>foo=a;    
document.addEventListener('mousedown', function() { doSomething(foo) }, false); 
foo=b;

doSomething(val){
alert(val);
}
</code></pre>

<p>so it should alert "a" not "b";</p>
