If you agree to using underscore.js , I recommend using its debounce :
$('#division').on('click', _.debounce(someFunction, 5000, true));
Also, here is a great article on how debouncing works .
If you want to flip your own debouncing, it's that simple:
$('#division').on('click', (function(func, wait, immediate) { var timeout, result; return function() { var self, args, callNow; function later () { timeout = null; if (!immediate) result = func.apply(self, args); } self = this; args = arguments; callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) { result = func.apply(self, args); } return result; }; }(someFunction, 5000, true))));
... just kidding, it just emphasizes the debounce inline function.
source share