Answer the question
In order to leave comments, you need to log in
Why was the result of the function not returned after a certain number of milliseconds?
function f(x) {
alert( x );
}
function delay(f, ms){
return function(arg){
return setTimeout(f(arg), ms);
}
}
var f1000 = delay(f, 3000);
var f1500 = delay(f, 5500);
f1000("тест");
f1500("тест2");
Answer the question
In order to leave comments, you need to log in
What did you want to get?
You have a direct call to f(arg); here is alert
To defer execution and pass an argument, you need to do something like this:
function f(x) {
alert( x );
}
function delay(f, ms){
return function(arg){
return setTimeout(function() { return f(arg); }, ms);
}
}
var f1000 = delay(f, 3000);
var f1500 = delay(f, 5500);
f1000("тест");
f1500("тест2");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question