title: How to call a method from another method within the same object in JavaScript?
body: <p>I'm just getting started in OO javascript so please bear with me.</p>
  
  <p>This works:</p>
  
  <pre><code>var myObj = {
       foo : function() {
              alert('hello');
              this.bar();
       },
       bar: function() {
              alert('world');
       }
  }
  </code></pre>
  
  <p>However if I do some other stuff after the hello alert in the "foo" method then the meaning of "this" changes from the object to whatever I last selected so using <code>this.bar()</code> doesn't execute the other method in the class. </p>
  
  <p>So I tried to cache "this" in a variable like so:</p>
  
  <pre><code>var myObj = {
       publicVars: {
              theObj : this
       },
       foo : function() {
              alert('hello');
              publicVars.theObj.bar();
       },
       bar: function() {
              alert('world');
       }
  }
  </code></pre>
  
  <p>But that didn't work either. So what is the solution?</p>
  
  <h2>EDIT</h2>
  
  <p>Here is my actual code:</p>
  
  <pre><code>var formObj = {
  
       validate : function(theForm) {
              $('input, textarea', theForm).each(function() {
                   var valueLength = $(this).val().length;
                   if (valueLength === 0) {
                          $(this).addClass('invalid');
                          this.listenForInput($(this)); // &lt;!------- this isn't working
                   }
              });
       },
       listenForInput : function(theField) {
  //          theField.keyup(function() {
  //               if ($(this).val().length &gt; 0) {
  //                      theField.removeClass('invalid');
  //               }
  //          });
              alert('I work!!!!');
       }
  
  } // end obj
  </code></pre>