Last active
December 18, 2015 17:48
-
-
Save mawatari/5820595 to your computer and use it in GitHub Desktop.
Timerで実行する処理が重たいとき等に。
This file contains 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
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