Promise系列01:初识Promise
来源:互联网 发布:淘宝美工风格 编辑:程序博客网 时间:2024/06/08 08:53
Promise 对象用于异步(asynchronous ) 计算.。一个Promise对象代表着一个还未完成,但预期将来会完成的操作。
// 传统写法step1(function (value1) { step2(value1, function(value2) { step3(value2, function(value3) { step4(value3, function(value4) { // ... }); }); });});
// Promises的写法(new Promise(step1)) .then(step2) .then(step3) .then(step4);
由以上代码可见,采用Promises接口以后,程序流程变得非常清楚,十分易读。
总的来说,传统的回调函数写法使得代码混成一团,变得横向发展而不是向下发展。
Promises规范就是为了解决这个问题而提出的,目标是使用正常的程序流程(同步),来处理异步操作。它先返回一个Promise对象,后面的操作以同步的方式,寄存在这个对象上面。等到异步操作有了结果,再执行前期寄放在它上面的其他操作。
0 0
- Promise系列01:初识Promise
- Promise系列02:Promise创建
- Promise系列03:Promise状态
- Promise系列05:Promise应用
- promise
- Promise
- Promise
- Promise
- Promise
- Promise
- Promise
- promise
- promise
- promise
- promise
- Promise
- Promise
- promise
- git pull 出错 fatal: Could not read from remote repository.Please make sure you have the correct acces
- android应用程序的启动流程
- mac命令行启动tomcat
- 网络营销工程师
- 判断一个括号字符串是否匹配正确
- Promise系列01:初识Promise
- 多线程编程(3):AsyncTask的基本用法
- 单点登陆实现方案
- $_SERVER
- csv身份证号码显示不正确问题
- mybatis使用bug:org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map java
- MySQL之char、varchar和text的设计
- Kodi ——6 Controls (24)6.24 Wraplist Container
- 使用函数rand5()来实现函数rand7()