how to assign functions in javascript?
<p>I'm new to Javascript and I just discovered the property keyword for defining functions for objects. I tried to refactor my websocket experiment using objects, but I can't get it to work.</p>

<p>This works (no objects):</p>

<pre><code>var ws = new WebSocket(something, somethingelse);
ws.onopen = function() {
   ws.send("hello");
   console.log("works");
}
</code></pre>

<p>But this doesn't:</p>

<pre><code>function MyObject() {
   this.ws = new WebSocket(something, somethingelse);
   this.ws.onopen = this.onOpen;
}

MyObject.prototype.onOpen = function() {
    this.ws.send("hello");   // undefined!
};
</code></pre>

<p>Why is ws undefined? Am I assigning the onOpen function incorrectly?</p>
