返回功能值

时间:2017-08-12 23:41:46

标签: javascript node.js watson-conversation

我有一个函数updateMessage,它会检查payload的值,通过函数checkWeather()调用weather API,并将该API的结果附加到finalResponse变量。

但是,当我在undefined函数中调用checkWeather()时,我会继续updateMessage

checkWeather函数运行正常,但出于某种原因,当我尝试返回其值时,它的范围就超出了范围。

function updateMessage(payload, response) {
    //Set var to JSON value
    let finalResponse = response.output.text;

    // Set var to function and return it
    weatherData = checkWeather(appCity, appST);

    return finalResponse.push(weatherData);
}
function checkWeather( ... )

可以在此要点here

中访问完整代码

1 个答案:

答案 0 :(得分:1)

如果您使用

更改return finalResponse.push(weatherData);语句
finalResponse.push(weatherData);
return finalResponse

它会起作用......

相关问题