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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:06:00+00:00 2026-06-11T00:06:00+00:00

I am working on a small script implementing deferreds and ran across this little

  • 0

I am working on a small script implementing deferreds and ran across this little bit of code that isn’t behaving as I would expect Javascript to.

var dfd = $.Deferred()
  , view  = $.get("filename.tmpl");

$.get("filename.json")
  .always(function (model) {
    dfd.resolve(model);
  });

$.when(view, dfd)
  .done(function (view, model) {
    // do stuff with view - even if there is no model
  });

And this works fine, but when I refactor to this it stops working:

var dfd = $.Deferred()
  , view  = $.get("filename.tmpl");

$.get("filename.json").always(dfd.resolve);

$.when(view, dfd)
  .done(function (view, model) {
    // do stuff with view - even if there is no model
  });

I don’t see any reason that this shouldn’t work. The function is expecting the first argument to be the model or undefined.

  • 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-11T00:06:02+00:00Added an answer on June 11, 2026 at 12:06 am

    When you do this:

    $.get("filename.json").always(dfd.resolve);
    

    instead of this:

    $.get("filename.json")
      .always(function (model) {
        dfd.resolve(model);
    });
    

    you will get a different object passed as the this pointer for the resolve() method. The second will call it in the context of dfd. The first will call it the context of the deferred object returned from your $.get() which is different.

    It important to remember that when passing a callback dfd.resolve just gets a pointer to the method. It does NOT set the context in which resolve will be called. That is set internally to the .always() method.

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

Sidebar

Related Questions

I am working on a small bit of script that will allow for easy
I wrote a small script that provided a URL (For example: code.google.com/ajax/123/1235/214) Would tell
I'm working through a small file upload script (learning experience) and I noticed that
I'm currently working on a small script that needs to use gtk.StatusIcon() . For
I'm working on this small script: basically it's mapping the list elements (with special
I'm working in a small PHP script that transform a SVG file into PDF
Currently I have this small script that makes it possible to check if a
I'm working on a small banner-rotation script that loads a random banner from the
I'm working on a small GreaseMonkey script where I would like to embed a
I have this small script I'm trying to get working on my webpage, its

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.