-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for
variable shadowing with destructuring
#2273
Comments
I think #643 definitely needs to be reexamined now (especially after reading #238). See my comment here. |
Yep, we both acknowledged that problem in #1552. The solution apparently isn't acceptable, though. |
I wasn't claiming credit |
Oh, me either. I was just making it clear that others have shared the same opinion, but there's pushback from @jashkenas. Pulling the declaration in would solve both problems (accidental shadowing, as your comment pointed out, and exposure of the iterator). |
Ahh -- gotcha |
Perhaps my pushback is mere confusion. What's the desired change here exactly?
... that indeed sounds like what we should be doing. |
@jashkenas: Gerald's comment, compiled: (function() {
var outerVar;
outerVar = "outer";
return function() {
return console.log(outerVar);
};
});
(function() {
var outerVar;
outerVar = "outer";
return function() {
var outerVar, _i, _len, _ref, _results;
console.log(outerVar);
_ref = [0];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
outerVar = _ref[_i];
_results.push(0);
}
return _results;
};
}); |
Yes -- that seems wrong. We shouldn't be shadowing there ... why are we? |
This change just broke some of my code, and I was surprised by it. I think the reason to do it the old way (pre- afdcdcf) is that it is natural to think of a list comprehension as a shortcut for defining an iterator function and calling it on a list of values, which makes what you're calling the loop variable names actually the names of the PARAMETERS to the iterator. I realize that's not the implementation, but it seems like a more natural mental model for what a list comprehension actually is. |
Note the lack of inner
var v
in the second.See also: #1552
The text was updated successfully, but these errors were encountered: