변수를 비동기 함수에서 가져 오는 방법은 무엇입니까?aysnc 함수에서 변수를 가져 오는 방법
다음과 같은 사항이 있으며이 비동기 함수에서 httpsResp 변수를 얻고 싶습니다.
var httpsResp;
var dfd = this.async(10000);
var httpsReq = https.request(httpOptions, dfd.callback(function (resp) {
httpsResp = resp.statusCode;
assert.strictEqual(httpsResp, correctResp, error.incorrectResp);
}), dfd.reject.bind(dfd));
httpsReq.end();
httpsReq.on('error', function(e) {
console.error(e);
});
console.info('Status Code: ' + httpsResp);
현재 httpsResp는 정의되지 않은 것으로 표시됩니다.
[내 변수가 함수 내부에서 수정 된 후에도 변수가 변경되지 않는 이유는 무엇입니까? - 비동기 코드 참조] (http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) – Barmar