我正在学习 JS Promise。我对如何在运行 cb 函数(需要 5 秒)后重新处理 f2 返回的承诺感到有点困惑。
var cb = function(){
console.log('5 sec');
}
var f2 = function(){
return new Promise((resolve,reject)=>{
setTimeout(cb, 5000);
console.log('Last line of f2')
resolve('5RESOLVED')
});
}
f2().then(res=>{
console.log(res)
})
Run Code Online (Sandbox Code Playgroud)
当前输出按以下顺序排列
我希望输出为 - Last line of f2 - 5 sec -5Resolved