简体   繁体   中英

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?

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();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM