Why are callbacks more “tightly coupled” than promises?

前端 未结 5 1123
Happy的楠姐
Happy的楠姐 2021-01-30 06:51

Can you explain me the following phrase (taken from an answer to Stack Overflow question What are the differences between Deferred, Promise and Future in Javascript?)?

W

5条回答
  •  天涯浪人
    2021-01-30 07:39

    The coupling is looser with promises because the operation doesn't have to "know" how it continues, it only has to know when it is ready.

    When you use callbacks, the asynchronous operation actually has a reference to its continuation, which is not its business.

    With promises, you can easily create an expression over an asynchronous operation before you even decide how it's going to resolve.

    So promises help separate the concerns of chaining events versus doing the actual work.

提交回复
热议问题