title: Global Javascript Event Handling Object Context
body: <p>I have the following problem in event handlers in Javascript. I've got an object that has a <code>mousemove</code> event handler like so:</p>
  <pre><code>function MyObject(){ }
  function MyObject.prototype = {
  
      currentMousePosition: null,
      onMouseMove: function(ev){
         this.currentMousePosition = this.getCoordinates(ev);
      },
      getCoordinates: function(ev){
          if (ev.pageX || ev.pageY)
              return { x: ev.pageX, y: ev.pageY };
  
          return { x: ev.clientX + document.body.scrollLeft - document.body.clientLeft, y: ev.clientY + document.body.scrollTop - document.body.clientTop };
      }
  
  };
  </code></pre>
  <p>The problem I'm trying to solve resolves around object context. Within my <code>onMouseMove</code> function it assigns the <code>currentMousePosition</code> property. Naturally this won't work because it's a static function handling the <code>mousemove</code> event.</p>
  <p>What I'm looking for is a technique/method to pass an object context in with my event handler. The best example that I can think of is the Google Maps API function <code>GEvent.bind()</code>.
  With it you can pass the object with the function you want to fire on the specified event. I'm essentially looking for the same thing.</p>