Skip to content

Instantly share code, notes, and snippets.

@malithmcr
Last active October 25, 2018 14:06
Show Gist options
  • Select an option

  • Save malithmcr/055bcc354f8cca799d65d6e042a87249 to your computer and use it in GitHub Desktop.

Select an option

Save malithmcr/055bcc354f8cca799d65d6e042a87249 to your computer and use it in GitHub Desktop.

Revisions

  1. malithmcr revised this gist Oct 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion throttle.js
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,4 @@ function throttle(fn, wait) {
    time = Date.now();
    }
    }
    }:
    }
  2. malithmcr created this gist Oct 25, 2018.
    16 changes: 16 additions & 0 deletions throttle.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /**
    * throttle
    * @param {fn} callback func
    * @param {wait} number - wait time
    * @public
    */

    function throttle(fn, wait) {
    var time = Date.now();
    return function() {
    if ((time + wait - Date.now()) < 0) {
    fn();
    time = Date.now();
    }
    }
    }: