title: How can I maintain control of the this keyword when extending prototypes in jQuery?
body: <p>I'm implementing a class-like structure in jQuery, but I'm having some trouble when I try to call some of my functions.</p>
  
  <p>This is how the structure is setup:</p>
  
  <pre><code>MyClass = function(name) {
      this.init(name);
  }
  $.extend(MyClass.prototype, {
      init: function(theName) {
          this.myFunction(); // works
          $('.myclass').each(function(){
              this.myFunction(); // doesn't work
          });
      },
      myFunction = function(){}
  });
  </code></pre>
  
  <p>The problem I'm having is that when I try to call one of my functions (e.g., <code>myFunction()</code>) from inside a jQuery block (like the <code>each()</code> construct above), I get the error "<code>myFunction() is not a function</code>."</p>
  
  <p>I think this has something to do with the <code>this</code> keyword changing its meaning inside the jQuery block, but I'm not sure. Any help would be appreciated!</p>