function jsoncall(){
$.getJSON("http://localhost:3000/data", function (data) {...});
$.getJSON("http://localhost:3000/data", function (data) {...});
}
jsoncall.callback(function(){
//do stuff
});
Something like the pseudocode above. Is there a method in JavaScript that considers async calls like the getJSON above?
function (data) {...}the callback? :)jsoncallis just like$.getJSON- you could simply dojsoncall = $.getJSONsince they are functionally equal. If you need to wait until it's done, then I would recommend looking into$.Deferredor ES6 Promises.function jsoncall(){ return $.getJSON(...) }and thenjsoncall().then(callback)But the deferred-implementation of jQuery is imo. something between not good and awful, depending on the version you're using. I'd reccomend you taking a look at "real" promises.