-
Notifications
You must be signed in to change notification settings - Fork 2k
wrong variable scope when using results of inline loop #3549
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
Comments
That IIFE is an implementation detail. The loop variables are scoped to the enclosing function, not the loop itself: for bar in bars
foo bar
console.log bar # bar is accessible here; its scope is not restricted to the for block. A questionable design, but it makes things consistent with variables defined on other block constructs, like if foo
bar = 42
console.log bar # bar is accessible here; its scope is not restricted to the if block. |
Feel free to weigh in here, if you've been bitten by this : #2518 |
No, this is different issue. #2518 is about using This usage of loop is shoort-cut for creating function that returns array. So why internal variable is visible to others? IMHO it is very wrong. next, @epidemian, yes, I cleanly understand that original Ecmascript's loop does not define it's own context and so, variable defined inside this loop is really defined in outer function's scope of that loop. But if we speak about CoffeeScript constructions, authors make theris own rules :) intuitive for that language. update for @epidemian: |
is converted to
So, now I cleanly understand "everything is value" concept. It really just wrap only resulting value and no more. Even So, I close issue. it's not a bug and is invalid feature. |
is rendered as
So, why
value
variable is declared not in enclosed scope, but in "local" scope?The text was updated successfully, but these errors were encountered: