I can do this:
require('zappajs') ->
@get '/':-> console.log(@response)
but when I try this
require('zappajs') ->
@get '/': -> foo()
foo = ->
console.log(@response)
@response is undefined. So obviously 'this' is now out of scope. I tried using the => function definition instead of -> which is meant to pass 'this' through ... but it makes no difference.
I can achieve the desired result using a @helper
require('zappajs') ->
@get '/':-> @foo()
@helper foo: ->
console.log(@response)
Is that the only way of doing this?
You're losing scope when you're calling your function like that foo(), to keep the scope, you have to call foo like that:
foo.apply(this) or foo.call(this)