You should use jQuery Promises
doSomething()
.then(doSomethingElseWhenThatsDone, orHandleAnError)
.then(doYetAnotherThingWhenThatsDone, orHandleAnError);
function doSomething(){
//set up some JSOM stuff
var dfd = $.Deferred();
context.executeQueryAsync(
function () {
dfd.resolve();
}, function (sender, args) {
dfd.reject(sender, args, errorMsg);
});
return dfd.promise()
}
http://stackoverflow.com/questions/22411220/how-do-i-get-the-executequeryasync-to-behave-more-synchronuslyhttps://stackoverflow.com/questions/22411220/how-do-i-get-the-executequeryasync-to-behave-more-synchronusly