I've a for-loop I'm looping through.
I want to make a custom modal and wait for a response before continue it.
How can I achieve this? I know I've to wait for a callback.
Like this example:
for(var x in array){
alert(x);
console.log(x);
}
It does exactly what I want to. But I want to have three buttons.
But alert is not part of javascript(? It's in the browser.)
So, do you guys have an idea?
I was thinking about doing something like this:
var run = true;
function foo(){
if (run){
setTimeout(foo, 500);
}
}
function stop(){
run = false;
}
foo();
and then wait for a stop which calls on a button click before continue. But is this really good practice?
Or use a lambda function as a parameter to the customAlert and a "global" variable that holds the current position of the array I'm going through and do this with functions. Like: Check if array is still holding keys greater than X.
Then do the function again and each time increase the global X.
Thank you lostsource for the code:
Oh, I got an idea; I'll simply use lostsource's solution inside an anonymous function, so I don't get global variables. Excellent.
(function(){
})();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…