3 ms·
What's up with these kind of childish slander of OSS projects being upvoted to the top? Anyway, funnily enough, this change was not only rectified on CoffeeScr
by epidemian 12y ago
What's up with these kind of childish slander of OSS projects being upvoted to the top?
Anyway, funnily enough, this change was not only rectified on CoffeeScript 1.9.1, but it was also a change that only affected code that relied of the names of compiler-generated variables.
foo = (@bar) ->
# Bad: "bar" is not declared anywhere
console.log bar
# Good: the parameter is "@bar", so that should be used instead
console.log @bar
Relying on a "bar" variable existing inside that function body is no different from relying on an "_i" variable exiting inside a look like:
for a in arr
console.log "the index is", _i
... which, BTW, would also break if upgrading to CoffeeScript 1.9, because the compiler-generated iterator variable would now be called "i" :)
Update: i misinterpreted something. What was rectified in CoffeeScript 1.9.1 was the addition of an "_at_" prefix for the generated parameters of `(@something) ->` functions, which broke Angular's dependency injection mechanism when using it like `(@$someAngularThingy) ->`. You still can't access the auto-generated "bar" parameter in the first snippet. If you access a "bar" variable inside that function, the auto-generated parameter is then named "bar1", which is the Right Thing to do :D
- ufo 12y agoDid the first example at least give a warning or did it silently succeed?
- epidemian 12y agoAlas, no, the compiler does not warn about that. I don't know if it should though, as accessing a "bar" variable inside that function might be legal if bar was assigned as global variable, which the CoffeeScript compiler has no way to track.
- ufo 12y agoAh, thats unfortunate... I do think giving a warning should be possible though. Coffescript has some weird variable scoping rules but the scopes are still static so the compiler you should be able to detect if you are accessing one of the compiler-generated internal variables.