Last active
December 12, 2015 04:08
-
-
Save tomoh1r/4711625 to your computer and use it in GitHub Desktop.
1. 「0」を出力する 2. 1秒待つ 3. 「1」を出力する 4. 1秒待つ 5. 「2」を出力する see http://techblog.yahoo.co.jp/programming/js_callback/
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
'use strict'; | |
(function(seq) { | |
var hoge = function(seq) { | |
// timeout の秒数 (ms) | |
var timeout = 1 * 1000; | |
// 与えられた配列の length が 0 なら終わり | |
if (seq.length == 0) return; | |
// 与えられた配列の length が 1 なら次は処理しないので終わり | |
console.log(seq[0]); | |
if (seq.length == 1) return; | |
// 1秒後に次の処理を実施する。 | |
setTimeout(function() { | |
// 与えられた配列の頭をとった後ろで処理をする | |
hoge([].slice.call(seq, 1)); | |
}, timeout); | |
}; | |
hoge(seq); | |
})([0, 1, 2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment