Skip to content

Commit 947d738

Browse files
committed
Autocomplete: Refactored _response() so that requestIndex is defined closer to where it's used.
1 parent 64a39d9 commit 947d738

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
*/
1717
(function( $, undefined ) {
1818

19-
// used to prevent race conditions with remote data sources
20-
var requestIndex = 0;
21-
2219
$.widget( "ui.autocomplete", {
2320
version: "@VERSION",
2421
defaultElement: "<input>",
@@ -416,21 +413,24 @@ $.widget( "ui.autocomplete", {
416413
this.source( { term: value }, this._response() );
417414
},
418415

419-
_response: function() {
420-
var that = this,
421-
index = ++requestIndex;
416+
_response: (function() {
417+
var requestIndex = 0;
422418

423-
return function( content ) {
424-
if ( index === requestIndex ) {
425-
that.__response( content );
426-
}
419+
return function() {
420+
var index = ++requestIndex;
427421

428-
that.pending--;
429-
if ( !that.pending ) {
430-
that.element.removeClass( "ui-autocomplete-loading" );
431-
}
422+
return $.proxy(function( content ) {
423+
if ( index === requestIndex ) {
424+
this.__response( content );
425+
}
426+
427+
this.pending--;
428+
if ( !this.pending ) {
429+
this.element.removeClass( "ui-autocomplete-loading" );
430+
}
431+
}, this );
432432
};
433-
},
433+
})(),
434434

435435
__response: function( content ) {
436436
if ( content ) {

0 commit comments

Comments
 (0)