Closed whoiscc closed 6 years ago
This unexpected situation could be eliminated if I add var on both variable_function's definition. Could the compiler act in this way, too?
CoffeeScript uses implicit scope. If we did that, we'd make it impossible to mutate a variable.
There were discussion to have an assignment operator for outer scope (the fork livescript uses :=
) though.
This behavior is awkward in my opinion, because when I was writing
dynamic_scoped_function
, I assumed thatvariable_function
would always be resolved to the outer one. In the original version of my buggy code where I found this problem, the innervariable_function
has nothing to do withdynamic_scoped_function
. They just happen to have the same name.This unexpected situation could be eliminated if I add
var
on bothvariable_function
's definition. Could the compiler act in this way, too?