如何在Synchronous中执行代码?

时间:2017-01-13 09:05:12

标签: javascript synchronization

var flag = displayMessage(message);             
if(flag=='true'){
    SaveAndGo(paramId,uniqueControlId);                             
}

想在displayMessage()函数调用完成后检查if条件,当前它检查if条件并行。我尝试了多种选择,但它对我不起作用。

1 个答案:

答案 0 :(得分:0)

you could try to do something like this. based on your requirement you have to modify your code. look this :

var val = 10;
function displayMessage(callback){
    alert("first function execute");
    return callback();
}

var flag = 10;
displayMessage(function(){
    if(flag == val){
        alert("Now condition code execute");
    }
})