Month: June, 2009

Getting confused between closures and eval()

19 June, 2009 (23:51) | JavaScript, Programming

I just saw a question regarding closures in JavaScript regarding code similar to the following:

for (i=0;i<n;i++){
foo.bind( function() { bar(i); } );
}

The question was why does every closure execute bar(i) with i as the value of n for every instance, rather than whatever the value of i was when the closure […]