title: Applying OOP with jQuery
body: <p>I'm working with jQuery and trying to apply some basic Javascript OOP principles to a set of functions that control hover behavior. However, I can't figure out how to get the &quot;this&quot; keyword to refer to the instance of the object I'm creating. My sample code is:</p>
  <pre><code>var zoomin = new Object();
  
  zoomin = function() {
         // Constructor goes here
  };
  
  zoomin.prototype = {
         hoverOn: function() {
            this.hoverReset();
            // More logic here using jQuery's $(this)...
         },
         hoverReset: function() {
            // Some logic here.
         }
         };
  
  // Create new instance of zoomin and apply event handler to matching classes.
  var my_zoomin = new zoomin();
  $(&quot;.some_class&quot;).hover(my_zoomin.hoverOn, function() { return null; });
  </code></pre>
  <p>The problematic line in the above code is the call to <code>this.hoverReset()</code> inside the <code>hoverOn()</code> function. Since <code>this</code> now refers to element that was hovered on, it does not work as intended. I would basically like to call the function <code>hoverReset()</code> for that instance of the object (<code>my_zoomin)</code>.</p>
  <p>Is there any way to do this?</p>