Skip to content

Instantly share code, notes, and snippets.

@mawatari
Last active December 18, 2015 17:48
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 mawatari/5820595 to your computer and use it in GitHub Desktop.
Save mawatari/5820595 to your computer and use it in GitHub Desktop.
Timerで実行する処理が重たいとき等に。
var i = 0, timer = function () {
console.log(++i);
setTimeout(timer, 1000);
};
timer();
// 回数制限付き
var i = 0, limitedTimer = function () {
console.log(++i);
var timerId = setTimeout(timer, 1000);
if (i >= 5) {
clearTimeout(timerId);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment