title: How to call a method inside a javascript object
body: <p>I'm just learning about how to best organize my javascript code, and I had a question regarding this small piece of code I wrote:</p>
  
  <pre><code>var reportsControllerIndex = {
      plotMapPoints: function(data) {
          //plots points
      },
  
      drawMap: function() {
          $.getJSON('/reports.json', function(data) {
              reportsControllerIndex.plotMapPoints(data);         
          });
      },
  
      run: function() {
          reportsControllerIndex.drawMap();
      }
  };
  </code></pre>
  
  <p>The question is regarding calling another function of reportsControllerIndex from within the reportsControllerIndex object.  I had first tried the following piece of code for the run function:</p>
  
  <pre><code>run: function() {
      this.drawMap();
  }
  </code></pre>
  
  <p>which worked perfectly.  However, I then quickly found doing this for the drawMap function:</p>
  
  <pre><code>drawMap: function() {
      $.getJSON('/reports.json', function(data) {
          this.plotMapPoints(data);         
      });
  }
  </code></pre>
  
  <p>does not work, since "this" would now refer to the callback function of the getJSON call. </p>
  
  <p>My solution was to just place reportsControllerIndex in front of all of the methods I want to call, but I was curious:  is there a more relative way for calling functions within an overall object like this (much like you'd do with a class in a standard OO language)?  Or am I forced to do it as I am currently, just calling the methods through the name of the object?</p>