Created
March 21, 2019 02:14
-
-
Save ksksue/4ec4ddd0a6d35215c30714681b44b535 to your computer and use it in GitHub Desktop.
非同期実行時にfunction内の引数が保持されるかの確認。結果保持される。
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 state = 0; | |
function hoge(a) { | |
if(state === 0) { | |
setTimeout(function(){console.log(a);},1000); | |
} else { | |
setTimeout(function(){console.log(a);},500); | |
} | |
state++; | |
} | |
hoge('1st'); | |
hoge('2nd'); | |
// result | |
// 2nd | |
// 1st |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment