javascript-tutorial / javascript-tutorial/en.javascript.info
Suggestion for Additions to Article on Promise
還沒有人認領這個 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.
-
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. -
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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
開啟 issue 所引用的 Promises 文章,並檢視其中現有的非同步程式設計討論。使用所提供的關於巢狀、可讀性和錯誤傳播的要點,新增一個聚焦於「Promises vs Callbacks」的章節,然後確認文章與周圍內容保持一致。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100