var a=(function(){ setTimeOut(()=>'data',1000) })()怎么样才能a() // 'data'var z=function(){ var promise=new Promise(function(sus,err){setTimeout(()=>{ this.f='data'sus() },1000)})return promise}var l=new z()l.then(function () { console.log(this.f)})...自己弄出来了
1 回答
慕的地6264312
TA贡献1817条经验 获得超6个赞
题主你的setTimeout写错了...
var a=(function(){
setTimeout(()=>console.log('data'),1000)
})()
Async/Await写法,算是函数内部的异步函数吧
function resolveAfter1Second(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x);
}, 1000);
});
}
async function dataShow(x) {
const a = await resolveAfter1Second(x);
return a;
}
dataShow("data").then(v => {
console.log(v);
});
添加回答
举报
0/150
提交
取消