I'm writing a basic node.js web server in coffeescript. When I write:
server.listen(3000, listener)
listener = () ->
console.log 'server listening on port 3000'
It starts the server, but doesn't print the message. So I gather that the callback isn't being called. On the other hand, when I do:
listener = () ->
console.log 'server listening on port 3000'
server.listen(3000, listener)
the message is printed on the console.
Why does the callback get called if it's defined before the call, but not if it's defined afterwards?