2017-08-12 369 views
-1

我有一个函数updateMessage,它执行​​的值检查,通过函数checkWeather()调用天气API,并将该API的结果附加到finalResponse变量。返回函数值

但是,当我在updateMessage函数内调用checkWeather()时,我总是收到undefined

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

+0

也许'checkWearher'是异步因为某些原因? – csanonymus

+0

'Array.prototype.push'不返回对该方法被调用的数组的引用,它可能与此处相同 – Vivick

回答

1

如果更改返回finalResponse.push(weatherData);语句访问

finalResponse.push(weatherData); 
return finalResponse 

它将工作...