I have 2 functions. The second one is faster than the first one,how could the function wait to complete first one’s work?
function1(); // slow
function2(); // fast
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JavaScript is imperative and single-threaded, it just works like this.
function2()won’t start untilfunction1()finishes.If by slow you mean calling asynchronously some external service via AJAX, then we’re talking.
function1()must provide some sort of callback so that when asynchronous request finishes,function2()is called:The implementation is trivial, e.g. using jQuery: