Created
June 6, 2013 16:38
-
-
Save tdd/5722940 to your computer and use it in GitHub Desktop.
Exo de programmation fonctionnelle à trous : Throttling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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