This is getting ridiculous…
Why do I get an error when I try to do this?
#...codecodecode...
g = generateGuid()
#...codecodecode...
generateGuid = ->
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace /[xy]/g, (c) ->
r = Math.random() * 16 | 0
v = (if c is "x" then r else (r & 0x3 | 0x8))
v.toString 16
All I want to do is call a private function…
driis is correct. To expand on his answer: You may be used to the JavaScript idiom
which allows you to call
generateGuidfrom anywhere within its scope (even before its definition). CoffeeScript doesn’t do this; instead, it compiles toThere are several reasons for doing this, but the long and short of it is that functions obey the same scoping rules as all other variables. Before a value has been assigned to
generateGuid,generateGuid()is an attempt to callundefined.Note that, due to the way asynchronous callbacks work in JavaScript, this will work: