2017-10-11 257 views

回答

1

通過使用Promise.prototype.then()

getInfoByName('title').then(function(value) { 
    console.log(value); 
}); 

它基本上不可能從SYNCHRONUS函數內部asynchronus調用的返回值。您可以將回撥傳遞給您的異步,並在then部分中調用它。請參閱How do I return the response from an asynchronous call?以獲取更多解釋和示例

+0

我做了一個控制檯日誌,它的工作原理,但如何從函數返回此值? –

-1

在函數'getInfo'中,您應該'解析'您想要返回的值。你可以在'getInfo'函數中的承諾中做到這一點。

+0

我做了 返回新的Promise(resolve => {resolve(「True」)} 舉例 –

2

您可以使用承諾then callback

getInfoByName('title').then((result) => { 
    console.log(result)) 
}