Skip to content

Instantly share code, notes, and snippets.

@marksteve
Last active August 29, 2015 14:03

Revisions

  1. marksteve revised this gist Jul 10, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions throttle.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,9 @@
    var throttle = function(f, cd) {
    var _this = this;
    var _cd = new Date;
    return function() {
    if (_cd - new Date < 0) {
    _cd = new Date(new Date().getTime() + cd);
    return f.apply(_this, arguments);
    return f.apply(this, arguments);
    }
    };
    };
  2. marksteve revised this gist Jul 10, 2014. 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
    @@ -4,7 +4,7 @@ var throttle = function(f, cd) {
    return function() {
    if (_cd - new Date < 0) {
    _cd = new Date(new Date().getTime() + cd);
    f.apply(_this, arguments);
    return f.apply(_this, arguments);
    }
    };
    };
  3. marksteve renamed this gist Jul 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. marksteve revised this gist Jul 10, 2014. No changes.
  5. marksteve created this gist Jul 10, 2014.
    17 changes: 17 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    var throttle = function(f, cd) {
    var _this = this;
    var _cd = new Date;
    return function() {
    if (_cd - new Date < 0) {
    _cd = new Date(new Date().getTime() + cd);
    f.apply(_this, arguments);
    }
    };
    };

    /*

    var shout = throttle(function() { console.log('SHOUT!'); }, 1000);
    setInterval(shout, 100);

    */