title: Call parent object method inside function with callback handler
body: <p>I'm calling ParentObject.doSomething() which inturn calls the WebService object to perform some ajax calls, and on success of the ajax call, the callback function is executed. But any parent function inside the callback function fails. </p>
  
  <p>I think this has something to do with scope resolution. I am not able to find a workaround for this problem. </p>
  
  <p>Is there a better architectural style to modularize the ajax services and model?</p>
  
  <p>I've create a jsfiddle also - <a href="http://jsfiddle.net/bzKXr/2/" rel="noreferrer">http://jsfiddle.net/bzKXr/2/</a></p>
  
  <pre><code>var ParentObject =  {
  
       doSomething: function(){
           document.write("Inside doSomething &lt;br /&gt;");
           var self = this;
           WebServices.firstService("some URL", self.successCallback);
       },
  
       changeData: function(data){
           //Manipulate data
           document.write("Inside changeData &lt;br /&gt;");
       },
  
       successCallback: function(jsonData){
           document.write("Inside successCallback &lt;br /&gt;");
           try {
               //Execution fails at this point. Possibly because of scope resolution
               this.changeData(jsonData);  
           }
           catch (error) {
               console.log(error);
               document.write(error);
           }  
       },
  };
  
  var WebServices = {
      firstService: function(url, successCallbackHandler){
          document.write("Inside firstService &lt;br /&gt;");
          //Get data using the URL
          //on success call successCallback
          successCallbackHandler("some data");
      }
  };
  
  
  $(document).ready(function() {
      ParentObject.doSomething();
  
  });
  ​
  </code></pre>