다음과 같은 코드가있는 경우 :비동기 - 변수를 전달하고 상황에 맞는
var asyncConfig = {};
var a, b;
for(var i = 0; i < someValue; i++) {
// do something with a
// do something with b
asyncConfig[i] = function(callback) {
func(a, b, callback); // func is async
}
}
// Include some more parallel or series functions to asyncConfig
async.auto(asyncConfig);
- 어떻게 당신이 변수의 값
a
및func
-b
그래서async.auto(asyncConfig)
가for
루프 후에 실행 될 때를 전달할 수를 ,a
및b
의 컨텍스트가 보존됩니까?
(func
의 모든 실행을위한 a
및 b
의 다른 컨텍스트.)
사전에 감사합니다! bind를 사용
[자바 스크립트 클로저 내부 루프 - 간단한 실제 예] (http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example) –