Skip to content

Instantly share code, notes, and snippets.

@LoganBarnett
Last active November 4, 2021 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoganBarnett/fa67015e6589ea514d1360e368b90480 to your computer and use it in GitHub Desktop.
Save LoganBarnett/fa67015e6589ea514d1360e368b90480 to your computer and use it in GitHub Desktop.
const fs = []
for(var i = 0; i < 3; ++i) {
fs.push(() => console.log(i))
}
fs.forEach(f => f())
// with explicit scope
const fs = []
const scope = { i: 0 }
for(; scope.i < 3; ++scope.i) {
fs.push(() => console.log(scope.i))
}
fs.forEach(f => f())
@logan-barnett-nwea
Copy link

The Ruby version:

for i in 0..3
  fs << lambda { puts i }
end
fs.each {|f| f.call()}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment