javascript-tutorial / javascript-tutorial/en.javascript.info
Suggestion for Additions to Article on Promise
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- HTML
- Star
- 25.5k
- Fork
- 4k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Mở bài viết về Promises được issue tham chiếu và xem lại phần thảo luận hiện có về lập trình bất đồng bộ. Thêm một phần tập trung “Promises vs Callbacks” sử dụng các ý được cung cấp về việc lồng nhau, khả năng đọc và lan truyền lỗi, sau đó xác nhận rằng bài viết nhất quán với nội dung xung quanh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100