title: Can you explain why this jQuery code works?
body: <p>I know that it works. I have implemented it successfully.</p>
  
  <pre><code>$("#vehicle_application_product_id").autocomplete({
        minLength: 2,
        source: function(request, response) {
            var term = request.term;
            if (term in cache) {
                response(cache[term]);
                return;
            }
  
            lastXhr = $.getJSON("/products/get_json_list", request, function(data, status, xhr) {
                cache[term] = data;
                if (xhr === lastXhr) {
                    response(data);
                }
            });
        }
    });
  </code></pre>
  
  <p>I am like a script kiddie with some of this stuff. I would NEVER be able to write that anonymous function myself, because of the following reasons:</p>
  
  <p>1) How did this person know to put the parameters "request" and "response" in the spec?</p>
  
  <p>2) The lines beginning "lastXhr = " is really mystifying. There is yet another anonymous function at the end. I realize that is probably a callback, something that is executed after the request is sent to the specified URL.</p>
  
  <p>3) That last conditional in the anonymous function:</p>
  
  <pre><code>if ( xhr === lastXhr ) {                                                                                      
      response( data );
  }
  </code></pre>
  
  <p>What the heck is that? If then third parameter, xhr, from this anonymous block is equal to the vaue returned by the .getJSON call ENCOMPASSING this anonymous block, return the data in the response?</p>
  
  <p>That is really the most difficult part to wrap my head around. And I notice that's 3 equals signs. This looks like pretty advanced code concepts, I would just appreciate what the rationale behind this is so that I can become a better coder.</p>