Skip to content

Instantly share code, notes, and snippets.

@mawatari mawatari/jsTimer.js

Last active Dec 18, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.