Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created May 7, 2012 23:26
Show Gist options
  • Save robotlolita/2631397 to your computer and use it in GitHub Desktop.
Save robotlolita/2631397 to your computer and use it in GitHub Desktop.
Let vs Var
// with let
for (let i = 0; i < children.length; ++i) {
let child = children[i]
setTimeout(function(){ doSomethingTo(child) }, 1000)
}
// without let
for (var i = 0; i < children.length; ++i) {
setTimeout(function(child) { return function() {
doSomethingTo(child)
}}(children[i]), 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment