Can anyone explain why this won’t work? I am just running this off of the CoffeeScript page’s “Try Coffeescript now” thing and my Chrome console logs the “nope” as you’ll see below
x = true
foo = (x = x) ->
console.log if x then "works" else "nope"
foo() # "nope"
If I had changed the x = true to y = true and ( x = x) to ( x = y ) in the argument definition
Thanks a million!
Seeing how the function is compiled makes the problem obvious:
As you can see, if the
xargument is null,xis assigned to it. So it’s still null.So, renaming the
xvariable toyfixes the problem: