function abc() {
var a = 1;
var func = function() {
var a = 2;
}
func();
alert(a);
}
Pay attention to the var, in the piece of code, the result of a will be 1, but if the var is omitted, the result will be 2, but I found Coffee not able to translate to this.
For example the following:
abc = ->
a = 1
func = ->
a = 2
return
func()
alert(a)
return
CoffeeScript, by design, doesn’t allow you to shadow a previously declared variable. Yet, there is one case where it still happens:
That will result in a
1. Becauseais function parameter, it’s local to the function scope.BTW, you could rewrite this as
where
do (a) -> a = 2is equivalent to((a) -> a = 2)().