eri*_*ric 2 javascript arrow-functions
在这个代码示例中:
let result = (async (global) => {
// other code here (includes await's; thus the async)
return 123;
})(this);
Run Code Online (Sandbox Code Playgroud)
代码有效,但返回的值无处可寻(不在其中result).有没有办法使用普通的return语句从这个函数中获取数据?
由于您使用了异步函数,因此它返回promise而不是value.
请尝试以下方法:
var result = (async (global) => {
// other code here (includes await's; thus the async)
return 123;
})(this);
result.then((res)=> console.log(res));Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81 次 |
| 最近记录: |