Skip to content

Instantly share code, notes, and snippets.

@ksksue
Created March 21, 2019 02:14
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 ksksue/4ec4ddd0a6d35215c30714681b44b535 to your computer and use it in GitHub Desktop.
Save ksksue/4ec4ddd0a6d35215c30714681b44b535 to your computer and use it in GitHub Desktop.
非同期実行時にfunction内の引数が保持されるかの確認。結果保持される。
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