new MyPromise(resolve => {
console.log(1);
resolve(3);
MyPromise.resolve().then(() => console.log(4)).then(() => console.log(5))
}).then(num => { console.log(num) }).then(() => { console.log(6) });
console.log(2)
用原生Promise和MyPromise分別運(yùn)行這段代碼,可以發(fā)現(xiàn)輸出順序不一樣,所以需要調(diào)整下then的實(shí)現(xiàn)。具體請(qǐng)看 http://www.itdecent.cn/p/4f3bef72758c
感謝作者分享~
Promise實(shí)現(xiàn)原理(附源碼)本篇文章主要在于探究 Promise 的實(shí)現(xiàn)原理,帶領(lǐng)大家一步一步實(shí)現(xiàn)一個(gè) Promise , 不對(duì)其用法做說明,如果讀者還對(duì)Promise的用法不了解,可以查看阮一峰老師的...