Last active
December 17, 2015 07:39
-
-
Save dotfold/5573946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var debounce = function (callback, wait) { | |
var timeout, | |
thisObj; | |
return function() { | |
var later = function() { | |
timeout = null; | |
callback.apply(thisObj); | |
}; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
}; | |
} | |
var fn = debounce(function() { | |
console.log('debounced'); | |
}, 500); | |
//fn(); | |
// call with interval > bouncerate | |
//setInterval(fn, 600); // should always call | |
// call with interval < wait period | |
var count = 0; | |
var intId = setInterval(function() { | |
fn(); | |
if (++count == 10) { | |
console.log(count); | |
clearInterval(intId); | |
} | |
}, 300); // should not call for 10 goes | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment