javascript-tutorial / javascript-tutorial/en.javascript.info

Suggestion for Additions to Article on Promise

未关闭
#2,807 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
HTML
星标
25.5k
派生
4k
PR 合并指标
30 天内没有已合并 PR

描述

We can add a section for Promises vs Callbacks to show the inherent advantages of Promise:

Like this :

At the simplest level, Promises are just a different way of working with callbacks. However, there are practical benefits to using them.

  1. One real problem with callback based asynchronous programming is that it is common to end up with callbacks
    inside callbacks inside callbacks
    , with lines of code so highly indented that it is difficult to read.
    Promises allow this kind of nested callback to be re-expressed as a more linear Promise chain that tends to be easier to read and easier to reason about.

  2. Another problem with callbacks is that they can make handling errors difficult. If an asynchronous function (or an asynchronously invoked callback) throws an exception, there is no way for that exception to propagate back to the initiator of the asynchronous operation.
    This is a fundamental fact about asynchronous programming: It breaks exception handling.
    The alternative is to meticulously track and propagate errors with callback arguments and return values, but this is tedious and difficult to get right.
    Promises help here by standardizing a way to handle errors and providing a way for errors to propagate correctly through a chain of promises.

Promises are therefore a powerful idiom for asynchronous programming.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

打开 issue 中引用的关于 Promises 的文章,审阅其中现有的异步编程讨论。添加一个重点明确的“Promises vs Callbacks”部分,使用所提供的关于嵌套、可读性和错误传播的要点,然后确认文章与周围内容保持一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
documentation
Issue 类型
文档
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。