有可能吗?这该怎么做?点击按钮时,我拨打function1
。如果条件为真(i==1
),则function1
暂停,并且仅在function2
完全执行后才执行以下代码。例如:
function1(i){
//some code here
if(i == 1){
function2(i); // call function2 and waits the return to continue
}
//the following code
}
function2(i){
//do something here and returns
}
答案 0 :(得分:0)
你走了:
function1(i){
//some code here
if(i == 1){
function2(i); // call function2 and waits the return to continue
}
//the following code
}
function2(i){
//do something here and returns
}
如果您的意思是function2
实际上是以某种方式异步:
function1(i){
//some code here
if(i == 1){
// call function2 and waits for return to continue
function2(i, function() {
// the following code
});
}
else {
//the following code
}
}
function2(i, callback){
//do something async here and return when complete
setTimeout(callback, 1000);
}