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.
foo=a;
document.addEventListener('mousedown', function() { doSomething(foo) }, false);
foo=b;
doSomething(val){
alert(val);
}
so it should alert "a" not "b";
something like:
demo: http://jsfiddle.net/gS9wu/1/