I'm learning CoffeeScript, and I've got one minor headache I haven't quite been able to figure out. If I create an object to do certain things, I occasionally need an instance variable for that object to be shared between methods. For instance, I'd like to do this:
testObject =
var message # <- Doesn't work in CoffeeScript.
methodOne: ->
message = "Foo!"
methodTwo: ->
alert message
However, you can't use var in CoffeeScript, and without that declaration message is only visible inside methodOne. So, how do you create an instance variable in an object in CoffeeScript?
Update: Fixed typo in my example so the methods are actually methods :)
message = "", but I really just want the variable to be null so I can set behavior based on existence rather than a more complex check to see if it's not "blank" etc.message = nullwhich is what you want no?message = nullI getParseError Unexpected 'TERMINATOR'testObjectto an object=and not a function= ()->