Pass function reference to function fails
<p>I'm currently playing around with <code>coffeescript</code> and websockets using <code>nodejs</code>.<br>
I created a <code>class SocketHandler</code> for managing websocket clients:</p>

<pre><code>class SocketHandler
    constructor: (@server) -&gt;
        @server.on "connection", @onClientConnect   

    onClientConnect: (socket) -&gt;
        console.log "client connected"
        socket.on "close", @onClientDisconnect

    onClientDisconnect: (code, message) -&gt;
        console.log "client disconnected"

ws = require "ws"
server = ws.Server { port: 8080 }
sockethandler = new SocketHandler server
</code></pre>

<p>When I run the script and a client connects I get the following error message:</p>

<pre><code>client connected
events.js:210
    throw new TypeError('listener must be a function');
    ^

TypeError: listener must be a function
[...]
</code></pre>

<p>I have no clue why this happens. In my view I'm passing a function reference to <code>socket.on</code> as the second parameter.</p>

<p>I tried to investigate further and tried to output <code>onClientDisconnect</code> to see what type it has.<br>
So I changed</p>

<pre><code>onClientConnect: (socket) -&gt;
    console.log "client connected"
    socket.on "close", @onClientDisconnect
</code></pre>

<p>to</p>

<pre><code>onClientConnect: (socket) -&gt;
    console.log "client connected"
    console.log @onClientDisconnect
    socket.on "close", @onClientDisconnect
</code></pre>

<p>resulting in getting an <code>undefined</code> value as output.<br></p>

<p>Now I'm really confused and I think I'm missing something fundamental at how the language works.<br>
Can anyone of you help me out?</p>