Skip to content

Instantly share code, notes, and snippets.

@ervinne13
ervinne13 / debouncing.js
Last active March 20, 2018 12:27
Debouncing / On Finished Typing in jQuery
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function () {
var context = this, args = arguments;
var later = function () {
timeout = null;