We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
myPromise
时隔一年多,回顾头来自己再写一次,巩固下,发现同样的this丢失问题依然困扰了我一会,基础还是不够牢固。
最重要的是,我发现先我以前模拟的Promise居然是错的!!!
我 then 方法内部用的居然是 同步操作。。。OMG,我一直没意识到,直到今天回顾才发现,卧槽,为何人家 then 里面用 setTimeout???
then
setTimeout
再结合经典面试题
new Promise(resolve => { console.log(1) resolve(2) }).then(res => console.log(res)) console.log(3) // 打印输出是 1 3 2
then 里面可不就是个微任务嘛。。。(但是setTimeout是宏任务,网上大多用它来实现Promise。但其实两者是有区别的!) PS:js里面有宏任务和微任务之分,vue源码中的nextTick也涉及这方面知识。可以看Tasks, microtasks, queues and schedules(宏任务与微任务)了解。
Promise
宏任务:
微任务:
尼玛,真尴尬啊!!!
果断把以前的内容给删了,这么尴尬的事情怎么能留下来呢!
The text was updated successfully, but these errors were encountered:
No branches or pull requests
myPromise
2019-12-12修改
时隔一年多,回顾头来自己再写一次,巩固下,发现同样的this丢失问题依然困扰了我一会,基础还是不够牢固。
最重要的是,我发现先我以前模拟的Promise居然是错的!!!
我
then
方法内部用的居然是 同步操作。。。OMG,我一直没意识到,直到今天回顾才发现,卧槽,为何人家then
里面用setTimeout
???再结合经典面试题
then
里面可不就是个微任务嘛。。。(但是setTimeout
是宏任务,网上大多用它来实现Promise
。但其实两者是有区别的!)PS:js里面有宏任务和微任务之分,vue源码中的nextTick也涉及这方面知识。可以看Tasks, microtasks, queues and schedules(宏任务与微任务)了解。
宏任务:
微任务:
尼玛,真尴尬啊!!!
果断把以前的内容给删了,这么尴尬的事情怎么能留下来呢!
阅读
The text was updated successfully, but these errors were encountered: