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);
})
It is a way to work around the problem of
thisescaping inside callback. Without this extra reference the code would look like this:Unfortunately!
thisinside response callback is not the same asthisoutside 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 namedthatfor the same purpose:This pattern also seems reasonable and readable.
Oh, and if you are curious about this syntax:
This is an assignment used as an expression. The value of assignment is the right-hand side, so this code is equivalent to: