title: Using $.getJSON() with callback within a Javascript object
body: <p>I'm trying to set up an object so that it has an encapsulated $.getJSON method. Here's my setup:</p>
  
  <pre><code>function Property(price, deposit){
    this.price = price;
    this.deposit = deposit;
    this.getMortgageData = function(){
      $.getJSON('http://example.com/index?p='+this.price+'&amp;d='+this.deposit+'&amp;c=?', function(data){
          this.mortgageData = data;
      });
    }
    return true;
  }
  </code></pre>
  
  <p>Now the problem seems to be that I don't have access to 'this' inside the getJSON callback function which makes sense.</p>
  
  <p>Is there a workaround for this type of function or am I just thinking about this totally the wrong way? I've only ever really coded using PHP OO before so JS OO is a bit new to me.</p>
  
  <p>Other things I've tried are:</p>
  
  <pre><code>  function Property(price, deposit){
    this.price = price;
    this.deposit = deposit;
    this.getMortgageData = function(){
      this.mortgageData = $.getJSON('http://example.com/index?p='+this.price+'&amp;d='+this.deposit+'&amp;c=?', function(data){
          return data;
      });
    }
    return true;
  }
  </code></pre>
  
  <p>But still, </p>
  
  <pre><code>var prop = new Property();
  prop.getMortgageData();
  // wait for the response, then
  alert(prop.mortgageData.xyz); // == undefined
  </code></pre>