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
From the CoffeeScript docs (emphasis added):
Because you don't have direct access to the var keyword, it's impossible to shadow an outer variable on purpose, you may only refer to it.
Is there a reason you need to shadow a
and can't just use a different identifier?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With