Forráskód Böngészése

Pass along arguments sent to debounce

Signed-off-by: Igor Vaynberg <[email protected]>
Kyle Gibson 12 éve
szülő
commit
de867bbba1
1 módosított fájl, 7 hozzáadás és 2 törlés
  1. 7 2
      select2.js

+ 7 - 2
select2.js

@@ -195,13 +195,18 @@
      *
      * @param quietMillis number of milliseconds to wait before invoking fn
      * @param fn function to be debounced
+     * @param thisobj object to be used as this reference within fn
      * @return debounced version of fn
      */
-    function debounce(quietMillis, fn) {
+    function debounce(quietMillis, fn, thisobj) {
+        thisobj = thisobj || undefined;
         var timeout;
         return function () {
+            var args = arguments;
             window.clearTimeout(timeout);
-            timeout = window.setTimeout(fn, quietMillis);
+            timeout = window.setTimeout(function() {
+                fn.apply(thisobj, args);
+            }, quietMillis);
         };
     }