当前位置:网站首页>Promise 中状态改变和回调执行先后顺序 和promise多次回调
Promise 中状态改变和回调执行先后顺序 和promise多次回调
2022-08-11 05:25:00 【陈阳羽】
Promise 中状态改变和回调执行先后顺序
<script>
/* Promise 中状态改变和回调执行先后顺序 1.当状态响应是同步执行的时候(也就是直接调用resolve/reject/throw) -先改变状态再响应回调 2.当状态响应式异步执行的时候 -先执行回调在改变状态 */
var p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("hello")
console.log("1")
}, 1000);
})
p.then(res => {
console.log(res);
})
console.log(p)
</script>
Promise 指定多个回调函数
<script>
/* Promise 指定多个回调函数 */
var p = new Promise((resolve, reject) => {
resolve("hello")
})
// 回调次数 1
p.then(res=>{
console.log(res,"回调第一次")
})
// 回调次数 2
p.then(res=>{
console.log(res,"回调第二次")
})
</script>
边栏推荐
- Realize data exchange between kernel and userspace through character device virtual file system (passed based on kernel 5.8 test)
- ASP.NET MVC 4中实现action的事务功能
- CMT2380F32模块开发8-Base Timer例程
- EMQX企业版试用笔记
- STM32学习笔记(白话文理解版)—按键控制
- 自定义形状seekbar学习
- aPaaS和iPaaS的区别
- 使用ActiveReports制作第一张报表
- Safety helmet identification system - escort for safe production
- Kotlin 增量编译的新方式 | 技术解析
猜你喜欢
SCNet: Semantic Consistency Networks for 3D Object Detection
Mei cole studios - sixth DjangoWeb application framework + MySQL database training
Joint 3D Instance Segmentation and Object Detection for Autonomous Driving
物联网IOT 固件升级
Maykel Studio - Django Web Application Framework + MySQL Database Third Training
CVPR2022——A VERSATILE MULTI-VIEW FRAMEWORK
STM32F407-浅~~析UART异步通信&USART_Init函数入口参数
产品经理与演员有着天然的相似
梅科尔工作室-华为云ModelArts第二次培训
Safety helmet identification system - escort for safe production
随机推荐
360° large field of view helmet recognition system-deep learning intelligent video analysis
arduino的esp32环境搭建(不需要翻墙,不需要离线安装)
音乐竞品分析:酷狗、QQ音乐、网易云、酷我、汽水音乐
蓝牙技术-简介
STM32学习笔记(白话文理解版)—按键控制
yolov3+centerloss+replay buffer实现单人物跟踪
MSP430学习总结——时钟UCS
CMT2380F32模块开发1-硬件
HTTP缓存机制详解
安全帽识别系统-解决监管难题
Safety helmet recognition system
产品如何拟定优化方案?
Wisdom construction site safety helmet identification system
STM32-串口常用寄存器和库函数及配置串口步骤
解决jupyter中import torch出错问题
【调试记录1】提高MC3172浮点运算能力,IQmath库的获取与导入使用教程
安全帽佩戴识别系统介绍
Introduction of safety helmet wearing recognition system
CMT2380F32模块开发3-GPIO例程
Pay “Attention” to Adverse Weather