Skip to content

Instantly share code, notes, and snippets.

@tdd
Created June 6, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdd/5722940 to your computer and use it in GitHub Desktop.
Save tdd/5722940 to your computer and use it in GitHub Desktop.
Exo de programmation fonctionnelle à trous : Throttling
Function.prototype.throttle = function(/* … */) {
var f = this;
// …
return function() {
// …
return f.apply(this, arguments);
};
};
// Protocole de test
function sayHi() { console.log(Date.now(), "Hiiiii…"); }
console.log(Date.now());
hiCoquine = setInterval(sayHi.throttle(1000), 100);
setTimeout(function() { clearInterval(hiCoquine); }, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment