Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:12:20+00:00 2026-06-17T22:12:20+00:00

When waiting for multiple deferred objects to complete, why does: $.when(tasks).then(function() { document.write(Completed all

  • 0

When waiting for multiple deferred objects to complete, why does:

$.when(tasks).then(function() {
    document.write("Completed all requests." + "<br/>");
});

execute immediately, yet

$.when.apply(null, tasks).then(function () {
    document.write("Completed all requests." + "<br/>");
});

waits until the tasks have completed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:12:21+00:00Added an answer on June 17, 2026 at 10:12 pm

    The when function does not take an array of deferreds. Rather, you pass each deferred as a separate argument. That’s exactly what apply is doing for you.

    The null being passed to apply is just because that’s what apply expects: the first argument is what the context of the function should be set to when its called, and the second argument is always an array, which will be expanded so that the function will be called as if all the items in the array have been passed in as separate arguments.

    Since for the purpose of when it makes no difference what context it’s being called with, null works just as well as anything else. I prefer to pass it jQuery itself:

    $.when.apply($, tasks).then(function () {
        // Whatever
    });
    

    since I think it looks cleaner, but that’s just me. It makes no difference whatsoever.


    If your browser supports native promises (or you’re using a polyfill) you can use its all method instead, which takes an array of promises directly:

    Promise.all(tasks).then(function (values) {
        // "values" is an array, with the results of each of the "tasks"
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Multiple ajax calls inside a each() function.. then do something once ALL
When using HTTP/1.1 Pipelining what does the standard say about issuing multiple requests without
If there are multiple threads all waiting on the same lock is it possible
All of a sudden my eclipse has stopped working. I have restarted it multiple
I am trying to write a class that will calculate checksums using multiple processes,
In my method I start multiple threads and then wait until they finish their
I have multiple consumer threads waiting on a CountDownLatch of size 1 using await()
I have a scenario where multiple users will be doing import processes, but all
I have the following code which could be called via multiple web-requests at the
I have a counter that's used by multiple threads to write to a specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.