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 9124011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:28:34+00:00 2026-06-17T06:28:34+00:00

I’m trying to figure out jQuery’s deferred api using the docs together with code

  • 0

I’m trying to figure out jQuery’s deferred api using the docs together with code that someone else wrote but find it very confusing. I wonder if looking at the functions below, you coudl explain

  1. what is the significance of dfd.resolve. Does it mean that the fadeOut is complete i.e. is it only executed once the fadeOut is complete? Is this passing the deferred object into the jQuery fadeOut function?

  2. what happens when promise.promise(); is returned? Why call promise(); on the promise property?

    Can you please explain this code a little

    hide: function() {
            if (this.el.is(":visible") === false) {
                return null;
            }
            promise = $.Deferred(_.bind(function(dfd) {
                this.el.fadeOut('fast', dfd.resolve)}, this));
            return promise.promise();
        },
    
  • 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-17T06:28:35+00:00Added an answer on June 17, 2026 at 6:28 am

    You’re right. dfd.resolve is passed as the callback to fadeOut, so that when the fade out is complete, the promise will resolve.

    promise = $.Deferred is misleading, since $.Deferred returns a Deferred object, not a promise. Calling .promise() on the deferred will return a promise.

    The difference between a deferred and a promise is that the promise is only used for registering callbacks (via always, done, fail, pipe, progress, or then), whereas the original deferred object also has a resolve method.

    To summarize: a promise is the same as the original deferred, minus the resolve method (and its related methods). This is used to protect your promise, so that you’re the only one with the ability to resolve/reject it. All the caller can do is add callback functions to it.

    Here’s a quote from the docs:

    The deferred.promise() method allows an asynchronous function to prevent other code from interfering with the progress or status of its internal request. The Promise exposes only the Deferred methods needed to attach additional handlers or determine the state (then, done, fail, always, pipe, progress, and state), but not ones that change the state (resolve, reject, notify, resolveWith, rejectWith, and notifyWith).


    To simplify this, let’s remove the underscore binding:

    function hide () {
      var deferred = $.Deferred(function(dfd) {
        $('div').fadeOut('slow', dfd.resolve)
      });
    
      return deferred.promise();
    }
    
    hide().then(function () {
      alert('Fade out is done!');
    });
    

    Here’s the fiddle: http://jsfiddle.net/fDUej/

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker

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.