2017-08-12 341 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 

它將工作...