2017-10-11 330 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)) 
}