我在first example的承诺页面上查看了MDN的JavaScript承诺。在Make a promise!
按钮上快速单击3次后,我得到以下结果:
1) Started (Sync code started)
1) Promise started (Async code started)
1) Promise made (Sync code terminated)
2) Started (Sync code started)
2) Promise started (Async code started)
2) Promise made (Sync code terminated)
3) Started (Sync code started)
3) Promise started (Async code started)
3) Promise made (Sync code terminated)
2) Promise fulfilled (Async code terminated)
1) Promise fulfilled (Async code terminated)
3) Promise fulfilled (Async code terminated)
我完全理解行Promise fulfilled
可以插入到promise开始输出块之间的任何位置(取决于promise值实际可用时),我不明白为什么Promise started
行是使用Started
和Promise made
行按顺序执行。
我希望在事件队列中放置一个事件,并在Promise made
指令完成后传递函数以创建一个在其自己的上下文中进行求值的promise。
似乎我错过了一些关于承诺的基本信息,但我无法确切地指出究竟是什么。