I have a CoffeeScript which I can’t call functions from. But if I declare an instance of it and add functions to the instance it works. What am I missing?
Function doesn’t get called:
class testClass
username: 'Fred'
this.testFunction = ()->
alert 'test'
test = new testClass
test.testFunction()
Function works:
class testClass
username: 'Fred'
test = new testClass
test.testFunction = ()->
alert 'test'
test.testFunction()
Within the
classbody,thispoints to the class itself, not its prototype. What you want isWriting
this.testFunction =, on the other hand, createstestClass.testFunction.