0

So, I have an array of function, e.g.:

var functions = [
                 function(){alert('foo');},
                 function(){alert('bar');}
                ];

Is it possible to call all the functions in this array after a Timeout, like this:?

setTimeout(/*insert function 1 and 2 here*/, 2000);
1
  • 1
    no. you can only pass ONE callback to settimeout. But you can have that callback call your OTHER functions for you. Commented Oct 6, 2014 at 15:47

1 Answer 1

2
setTimeout(function(){
    for (var n = functions.length, i = 0; i < n; i++) functions[i]();
}, 2000);
Sign up to request clarification or add additional context in comments.

1 Comment

@Ood You could choose this answer as "accepted" if it solve your problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.