Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Created November 30, 2014 15:22
Show Gist options
  • Save RyoSugimoto/ab4b142d1aab0ba17a42 to your computer and use it in GitHub Desktop.
Save RyoSugimoto/ab4b142d1aab0ba17a42 to your computer and use it in GitHub Desktop.
var throttle = (function () {
var interval = 500; // 間引き間隔
var lastTime = new Date().getTime() - interval;
return function () {
// 最後に実行した時間から間引きしたい時間が経過していたら実行
if ((lastTime + interval) <= new Date().getTime()) {
lastTime = new Date().getTime();
// 処理
}
};
}());
var debounce = (function () {
var interval = 500;
var timer;
return function () {
clearTimeout(timer);
timer = setTimeout(function () {
// 処理
}, interval)
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment