3 ms·
For the record, you can also create scope without a closure using with (or let, if it's available.) for (var i = 1; i < 10; ++i) { with({i:i}) // let (
by Cushman 16y ago
For the record, you can also create scope without a closure using with (or let, if it's available.)
for (var i = 1; i < 10; ++i)
{
with({i:i}) // let (i=i)
{
setTimeout( function( ) { alert( i ) }, i * 250 );
}
}
will do what you intend. If let is available, for (let i = 1; etc. will do the same thing without the cruft.