From de867bbba1be692231c200985bf31bf820a1c8a3 Mon Sep 17 00:00:00 2001 From: Kyle Gibson Date: Mon, 27 Aug 2012 12:09:47 -0400 Subject: [PATCH] Pass along arguments sent to debounce Signed-off-by: Igor Vaynberg --- select2.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/select2.js b/select2.js index 435e31aa..b0d09b83 100755 --- a/select2.js +++ b/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); }; }