5 ms·
The addition of the Let statement to ES6 makes this discussion moot, while bypassing coffeescript's sketchy globality.
by WalterSear 13y ago
The addition of the Let statement to ES6 makes this discussion moot, while bypassing coffeescript's sketchy globality.
- raganwald 13y agoCoffeeScript's "do" syntax replicates the let semantics now :-)
- WalterSear 13y agoAnd google's traceur compiler allows you to use all of ES6 now without coffeescript too. https://code.google.com/p/traceur-compiler/ https://code.google.com/p/traceur-compiler/
- camus 13y agobut traceur is not compatible with IE8.
- likeclockwork 13y agoYou should only need 'do' in the same place where you'd need it in javascript. (You're generating a closure that needs to close over variables that are likely to change, such as within a for loop..) Otherwise, just name your variables sensibly! The smaller the scope, the terser the name is, the greater the scope the more verbose the name should be. It's strange to me that anyone would miss block scoping or ever get 'bit' by this -feature-. I found it perfectly understandable after reading the docs. I really can't imagine why someone would feel compelled to rely on shadowing.. why would you want to name two variables the same thing within a nested context? And why would you ever nest your contexts so deeply that you have literally no recollection of what goes on above? I really can't imagine how people are structuring their source files if this is a problem. When would a closure every shadow a variable that ISN'T a parameter in the new context? All the examples I've seen of this being a problem are contrived and brittle-looking. I appreciate your writing on this stuff raganwald, but.. honestly, I think this a problem for sloppy programmers who don't jive with coffeescript being an opinionated language, and they'll disregard any advice you give them because they want the freedom to "safely" write hard to reason about code.
- epidemian 13y ago> The addition of the Let statement to ES6 makes this discussion moot I don't think it does. The JS broken behaviour described in the article is that if you happen to forget the "var" keyword when assigning a variable then you will create a global variable. "let" is great, but it doesn't fix that problem.
- masklinn 13y ago> The JS broken behaviour described in the article is that if you happen to forget the "var" keyword when assigning a variable then you will create a global variable. Use strict mode, problem gone. (alternatively, jshint/jslint or a good IDE will warn about implicit global declarations, it's not a very difficult pattern to check for)