1

Don't make it duplicate please. I am in middle of a big problem. I am working on a javascript code with thousands of lines of code. My problem is:

methodA is called from its own class.

methodA{  
    doSomething(abc, def, function(obj){  
        obj.getName();  
    });  
}  

doSomething(abc, def, callback){  
// codes....
callback(new XYZ());  
}

In XYZ class constructor I am using a couple of Jquery Deffered objects(with ajax calls). So my problem is at obj.getName() I am getting error that this.name is not defined. So how can I ensure that entire new XYZ() execution ends completely(all ajax calls, callbacks etc.) when the control comes to obj.getName() function ?

Thanks

chridam
  • 100,957
  • 23
  • 236
  • 235
mukund
  • 2,866
  • 5
  • 31
  • 41

2 Answers2

1

You can use function call back for this purpose. more can be searched on google by jquery deferred As shown here

var jqDeferred = doSomething(abc,def,function(obj){

});

jqDeferred.done(function(){
obj.getName();  
})


doSomething(abc,def,callback)
{

}
Community
  • 1
  • 1
anirban
  • 674
  • 1
  • 7
  • 21
0

you can use .when and .then => http://api.jquery.com/jquery.when/

methodA{  
    doSomething(abc, def, function(obj){  
        $.when(callback(new XYZ())).then(obj.getName());  
    }); 
Amin Jafari
  • 7,157
  • 2
  • 18
  • 43