Skip to content
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

variant overwrited in loops #2920

Closed
sssbit opened this issue Apr 10, 2013 · 2 comments
Closed

variant overwrited in loops #2920

sssbit opened this issue Apr 10, 2013 · 2 comments
Labels

Comments

@sssbit
Copy link

sssbit commented Apr 10, 2013

foo = 'globalvar'

bar = do ->
for foo in [1..5]
alert foo

alert foo # -> 6

the variant 'foo' in that function will overwrite the "foo = 'globalvar'".
so i think we alway need to create the local 'foo' var in "for foo in ..", "for foo of .." regardless of the 'foo' variant has been defined before.

@davidchambers
Copy link
Contributor

You shouldn't be shadowing variables. Jeremy has said this many times and I agree. Things that are different should have different names.

@davidchambers
Copy link
Contributor

See, for example, #2697.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants