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

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.

主站蜘蛛池模板: 蒙自县| 佛坪县| 阳泉市| 萨嘎县| 宁武县| 江孜县| 平凉市| 青铜峡市| 石景山区| 巴林左旗| 越西县| 霍林郭勒市| 迁西县| 天台县| 磐石市| 巴彦县| 长宁县| 阿拉善左旗| 土默特右旗| 博客| 清苑县| 甘谷县| 北海市| 木里| 哈密市| 阿拉善右旗| 邢台市| 河东区| 垫江县| 波密县| 洪江市| 哈密市| 芒康县| 饶河县| 老河口市| 衡阳市| 望谟县| 司法| 乐陵市| 浪卡子县| 花莲县|