I am very new to coffeescript, and I have been trying to find a way to make publicly accessible class members. If I run the following code:
class cow
n = 7
moo: ->
alert("moo")
bessie = new cow
alert(bessie.n);
It will show that bessie.n is undefined. The only solution I can find is to make getters and setters like n: -> n and setN: (value) -> n = value. I then must use function calls instead of simple property accesses. This feels cumbersome for a language which sells itself based on syntactic sugar.
Is there something I missed in the documentation that makes it easier to make classes with simple public members? What is the best practice for this?
It’s no different from setting methods.
Just try this
Doing only
Will just set private variable inside the class closure.
Use try coffeescript link on http://coffeescript.org/ to see what it compiles to.