Skip to content

Instantly share code, notes, and snippets.

@boopathi
Forked from mkuklis/gist:1011477
Created June 11, 2011 19:41

Revisions

  1. @mkuklis mkuklis created this gist Jun 7, 2011.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    function debounce(fn, wait) {
    var timeout = null;
    return function () {
    clearTimeout(timeout);
    var args = arguments;
    var ctx = this;
    timeout = setTimeout(function () {
    fn.apply(ctx, args);
    }, wait);
    }
    }

    function print(value) {
    console.log(value);
    }

    var printD = debounce(print, 100);
    printD(1);
    printD(2);
    printD(3);