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

  • SEARCH
  • Home
  • 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 6745217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:10:40+00:00 2026-05-26T12:10:40+00:00

Say you have the following piece of code: function someProcess() { var deferred =

  • 0

Say you have the following piece of code:

function someProcess() {
    var deferred = $.Deferred();

    apiCall(function (recvData) {
        deferred.resolveWith(null, [recvData]);
    });

    return deferred.promise();
}

function mainFunction() {
    $.when(someProcess())
        .then(someOtherProcess);
}

In this example I only need to wait for a single deferred to be resolved. In this case, what is the difference (if any) between writing the second function as above versus writing it like this:

function mainFunction() {
    someProcess()
        .then(someOtherProcess);
}

I mean, I like writing it the first way because it makes it clear that we’re using jQuery deferred objects, but I’m curious if it’s necessary in this case.

edit: I fixed a typo in the then() call. Thanks for catching that.

edit: Thanks for the answer nrabinowitz. I think you have nailed the points that I was not sure about in regard to using when() vs. using a raw jQuery deferred object instance. I went and fixed my code again to return a promise instead of the entire deferred object. That is how I do it in my actual code right now, just forgot to add it here.

  • 1 1 Answer
  • 2 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-05-26T12:10:41+00:00Added an answer on May 26, 2026 at 12:10 pm

    I haven’t used custom Deferred objects, but my understanding is that there are two differences in your examples:

    • Using $.when() allows you to arbitrarily add more deferred objects to be handled by your handlers. Obviously, not a big deal, since you’d have to change that line of code either way to add more deferreds.

    • $.when() only gets the Promise object, not the whole deferred object, which if I understand correctly is a consistency measure to hide the deferred’s state-changing methods (e.g. resolve()), only exposing handler hooks and state inspection methods. This seems like good practice, but in your example you could do the same thing by calling someProcess().promise() instead of $.when(someProcess()).

    So I think you’re right – both methods will work, but the main benefit of using $.when() is to make the code more legible and set expectations appropriately for other programmers. Using either $.when() or deferred.promise() will additionally help protect against some less competent coder messing with the state of your deferred in a confusing way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have the following piece of code: public class Event { }
Say I have the following piece of java code ArrayList<Double> myList = new Double[100];
Say I have the following piece of code: edge(a, b). edge(a, c). edge(a, d).
I have the following piece of code within my stored procedure , I know
I have the following piece of code, just wanted to check who will call
I have the following code: public function Application() { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
I have the following piece of code: self.ignore_dir_extensions = ['xcodeproj'] item = repr(extension.split('/')[0]) print
Say I have a piece of XML that looks like the following: <row Johnson&amp;Johnson="good"
I have a piece of Perl code somewhat like the following (strongly simplified): There
Let's say I have following ASP.NET Web Form engine code, how can I express

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.