This is a common error in CoffeeScript. Look at the compiled JavaScript:
Example = (function() {
var getText;
Example.text = 'Hello world! ;)';
getText = function() {
return this.text;
};
function Example() {
alert(getText());
}
return Example;
})();
Using @
in the class definition creates a static method or variable. That is, it's attached to the class object.
If you're trying to make it an instance variable, set it in your constructor.
constructor: ->
@text = 'Hello world! ;)'
alert(getText())
If you're trying to access the static property, refer to the class name.
getText = ->
Example.text