官术网_书友最值得收藏!

Why do we need promise in JS?

Promises.js is a JavaScript library that promises asynchronous I/O operations such as reading and writing on a file. Whenever there is a callback method that involves making all operations related to I/O, they are to be made asynchronous. This extra callback parameter confuses our idea of what is the input and what will be its return value. It never works with control flow primitives. It also doesn't handle errors thrown by a callback method.

So, we need to handle errors thrown by a callback method, but also need to be careful not to handle errors thrown by the callback method. By the time we are done with this, our code will be a mess of error handling.

Despite all this mess of error handling code, we are still left with the problem of the extra callback parameter hanging around. Promises help you naturally handle errors, and write cleaner code by not having callback parameters.

主站蜘蛛池模板: 兴文县| 云阳县| 中宁县| 丽江市| 故城县| 安仁县| 苏尼特右旗| 娱乐| 汕头市| 青海省| 庐江县| 清镇市| 通榆县| 昂仁县| 卓资县| 五河县| 钟山县| 卓尼县| 喀什市| 灵山县| 府谷县| 阆中市| 革吉县| 宜阳县| 老河口市| 增城市| 义乌市| 靖江市| 虎林市| 曲周县| 达拉特旗| 丰台区| 安国市| 临沧市| 平武县| 文水县| 北川| 四川省| 盐山县| 兰考县| 吴川市|