http://es6.ruanyifeng.com/#do...这个是阮一峰老师关于Promise.resolve()参数的解读,其中参数是thenable对象时,Promise.resolve方法会将这个对象转为 Promise 对象,然后就立即执行thenable对象的then方法。问题来了:new Promise(resolve => {resolve(1);Promise.resolve({ then: function(resolve, reject){ console.log(2);
resolve(3)
}
}).then(t => console.log(t))console.log(4);}).then(t => console.log(t));console.log(5);控制台输出:4 5 2 1 3下面按照最开始的理解,将上述代码进行转换new Promise(resolve => {resolve(1);new Promise(resolve=>{ console.log(2);
resolve(3)
}).then((t) => console.log(t));console.log(4);}).then(t => console.log(t));console.log(5);控制台输出 2 4 5 3 1
添加回答
举报
0/150
提交
取消