这个问题在这里已有答案:
在这个代码示例中:
let result = (async (global) => { // other code here (includes await's; thus the async) return 123; })(this);
代码有效,但返回的值无处可寻(不在 result 中) . 有没有办法使用普通的return语句从这个函数中获取数据?
result
由于您使用了异步函数,因此它返回一个promise而不是一个值 .
请尝试以下方法:
var result = (async (global) => { // other code here (includes await's; thus the async) return 123; })(this); result.then((res)=> console.log(res));
1 回答
由于您使用了异步函数,因此它返回一个promise而不是一个值 .
请尝试以下方法: