Skip to content

Instantly share code, notes, and snippets.

@olov
Created September 4, 2013 21:45
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 olov/6443290 to your computer and use it in GitHub Desktop.
Save olov/6443290 to your computer and use it in GitHub Desktop.
es6 loop variable bindings
// will this example
let arr = [];
for (let x = 0; x < 5; x++) {
x++;
arr.push(function() { return x; });
}
// ..be semantically equivalent to this?
let arr = [];
for (let x_ = 0; x_ < 5; x_++) {
let x = x_;
{
x++;
arr.push(function() { return x; });
}
x_ = x;
}
@allenwb
Copy link

allenwb commented Sep 4, 2013

yes, that is a valid equivalence for this simple case. but there are some complicaiton. See the thread that starts with https://mail.mozilla.org/pipermail/es-discuss/2012-February/020272.html

@olov
Copy link
Author

olov commented Sep 5, 2013

Thanks for commenting @allenwb. I guess I wondered whether this transformation was valid for any loop body and it seems that may or may not be the case. Looking forward to seeing the semantics nailed down! cc @Benvie

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