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

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.

主站蜘蛛池模板: 景谷| 平乐县| 铜陵市| 蕉岭县| 寿宁县| 临夏市| 林周县| 望谟县| 阜平县| 澎湖县| 高碑店市| 济宁市| 遂川县| 宣汉县| 正定县| 东至县| 吴旗县| 凤翔县| 山阳县| 达尔| 平塘县| 昆明市| 阳东县| 尚志市| 保德县| 沙坪坝区| 方山县| 甘南县| 包头市| 平塘县| 北宁市| 中西区| 木里| 揭阳市| 乐亭县| 类乌齐县| 邯郸县| 昌邑市| 纳雍县| 白山市| 石台县|