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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:12:11+00:00 2026-06-05T22:12:11+00:00

Kept on seeing this pattern in code, but couldn’t find any reference to it

  • 0

Kept on seeing this pattern in code, but couldn’t find any reference to it in google or SO, strange. Can someone point me to reference for this.async() function?

  var done = this.async();
  // ...
  $.get(path, function(contents) { // or some other function with callback
    // ...
    done(JST[path] = tmpl);
  })
  • 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-05T22:12:12+00:00Added an answer on June 5, 2026 at 10:12 pm

    It is a way to work around the problem of this escaping inside callback. Without this extra reference the code would look like this:

    $.get(path, function(contents) { // or some other function with callback
      //Wrong! `this` might no longer point to your object
      this.done(JST[path] = tmpl);
    })
    

    Unfortunately! this inside response callback is not the same as this outside of it. In fact it can be anything, depending on what $.get (calling the callback using) decides it to be. Most of the people use extra reference named that for the same purpose:

    var that = this;
    // ...
    $.get(path, function(contents) { // or some other function with callback
      // ...
      that.async(JST[path] = tmpl);
    })
    

    This pattern also seems reasonable and readable.

    Oh, and if you are curious about this syntax:

    done(JST[path] = tmpl)
    

    This is an assignment used as an expression. The value of assignment is the right-hand side, so this code is equivalent to:

    JST[path] = tmpl;
    done(tmpl);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
Can someone tell me how to change directories using FtpWebRequest? This seems like it
I kept looking for answer but didn't find one. I have a virtual env
I kept on receiving this error Deprecated: Assigning the return value of new by
Disclaimer : I kept this because some things may be useful to others, however,
Where Linux/Unix environment variables are kept? How can I add my own environment variable
I see that tax information is kept at order level but I cannot see
I know there are other questions that are very similar to this, but their
Kept getting DATABASE_URL does not match any of your databases ! Could not resolve
I kept getting this error when I use delayed_job + Rails 3.1 + ActionMailer

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.