Try using a fat arrow for the anonymous function:
setDatamember: ->
someFunction (response) =>
@datamember = response
@emit 'init'
Also, you'll need to call the correct function in the constructor:
constructor: ->
@setDatamember()
In general, avoid fat arrows on methods - the way Coffee-Script implements this does some bad things to memory usage. Also, it will rarely be necessary.
However, anonymous functions that refer to this
will almost always need fat arrows. this
is not held in closure like normal variables, and will only be set by binding (Function.prototype.bind
) or by calling it as an object method (obj.myMethod()
will set this
to obj
in myMethod
).