当前位置:网站首页>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>
边栏推荐
猜你喜欢

MSP430学习总结(二)——GPIO

关于安全帽识别系统,你需要知道的选择要点

Introduction of safety helmet wearing recognition system

梅科尔工作室-DjangoWeb 应用框架+MySQL数据库第六次培训

Maykle Studio - HarmonyOS Application Development First Training

Mei cole studios - sixth DjangoWeb application framework + MySQL database training

STM32-中断优先级管理NVIC

ActiveReports报表分类之页面报表

360°大视野安全帽识别系统-深度学习智能视频分析

关于接口响应内容的解码
随机推荐
The working principle and industry application of AI intelligent image recognition
【调试记录1】提高MC3172浮点运算能力,IQmath库的获取与导入使用教程
Hard hat recognition algorithm
关于mmdetection框架实用小工具说明
Zhejiang University School of Software 2020 Guarantee Research Computer Real Question Practice
梅科尔工作室-HarmonyOS应用开发第四次培训
net6的Web MVC项目实现限流功能
音乐竞品分析:酷狗、QQ音乐、网易云、酷我、汽水音乐
Wisdom construction site safety helmet identification system
The selection points you need to know about the helmet identification system
vscode插件开发——代码提示、代码补全、代码分析(续)
华为云IOT平台设备获取api调用笔记
Waymo dataset usage introduction (waymo-open-dataset)
Mei cole studios - deep learning second BP neural network
MSP430学习总结——时钟UCS
STM32学习总结(二)——GPIO
LiDAR Snowfall Simulation for Robust 3D Object Detection
SCNet: Semantic Consistency Networks for 3D Object Detection
Safety helmet recognition - construction safety "regulator"
自定义形状seekbar学习--方向盘view