user160820
user160820

Reputation: 15200

Waiting until callback function is executed

I have a JavaScript class where pass options object in init function. this options object also contains a callback function

this callback function is a globally defined function which create Ajax Request and updates the contents.

After the contents are updated, I want to register some event on the controls returned by the Ajax

Is there a way that the Class method (which calls the callback function) waits util the contains are updated and then registers the events?

Upvotes: 0

Views: 76

Answers (1)

jeremy
jeremy

Reputation: 10057

In order to do this, you have to pass another callback the first callback. Something like:

var feedDog = function(callback){
    fedDog = true; //feed the dog

    callback(function(){
        alert("This will alert as a callback to feedDog's callback.");
    });
};

feedDog(function(callback){
    alert("Fed dog");
    callback();
});

Upvotes: 1

Related Questions