Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: