이것은 AWS Lambda에서 게시하기 위해 작성된 응용 프로그램의 nodeJS 코드 너겟입니다. 즉 callProcess이 근무하고있다 -콜백 함수에서 nodeJS의 변수 범위 지정
가function speech2(intent, session, callback) {
let country;
const repromptText = null;
const sessionAttributes = {};
let shouldEndSession = false;
let speechOutput = 'old text';
callProcess('New York', function (error, data) {
if (!error) {
speechOutput = data;
console.log(speechOutput);
}
else {
console.log(error.message);
}
});
// Setting repromptText to null signifies that we do not want to reprompt the user.
// If the user does not respond or says something that is not understood, the session
// will end.
callback(sessionAttributes,
buildSpeechletResponse(intent.name, speechOutput, repromptText,
shouldEndSession));
}
가 CONSOLE.LOG (speechOutput)가 제대로 도시에 대한 처리 정보를 표시 하드 "뉴욕"여기 코드 - callProcess 기능은 기본적으로 내가 통과하고있는 도시에 대한 몇 가지 처리 정보를 반환 . 그러나 speechOutput이있는이 함수의 끝에있는 콜백은 여전히 '이전 텍스트'를 참조하고 있습니다. 즉, 함수 내에있는 처리 된 정보를 사용하여 변수를 덮어 쓸 수 없습니까? 콜백 내에서 어떻게해야합니까?
여기에 도움을 주시면 감사하겠습니다. 미리 감사드립니다.
'callProcess()', 너무 콜백 (I 가정) 비동기 'callProcess'는 당신이 마지막에'callback()'을 호출 할 때까지 시작되지 않습니다. callProcess() 콜백 내에서'callback()'을 호출하여 해당 값을 캡처해야합니다. –