当前位置:网站首页>promise 改变状态的方法和promise 的then方法
promise 改变状态的方法和promise 的then方法
2022-08-11 05:25:00 【陈阳羽】
promise 改变状态的方法
<script>
/* promise 改变状态的方法 1.resolve() | pending==>fulfilled 2.reject()返回失败 | pending==>rejected 3.throw抛出错误 | pending==>rejected */
var p =new Promise((resolve,reject)=>{
reject()
})
console.log(p)
</script>
promise 的then方法
<script>
/* promise 的then方法 1.如果promise.then抛出错误 -则回调函数返回值状态为rejected 2.如果promise.then中return -非promise对象数据则返回值为数据值 3.如果promise.then中return新的promise -返回的状态 = 新的promise状态 -返回值 = 新的Promise的返回值 */
var p = new Promise((resolve, reject) => {
resolve('hi');
})
var th = p.then(res => {
// console.log(res)
// throw "cuole"
// return "hello"
return new Promise((resolve,reject)=>{
// resolve('success')
// reject("nope")
})
}, fild => {
console.log(fild)
})
console.log(th)
</script>
边栏推荐
猜你喜欢
KANO模型——确定需求优先级的神器
STM32-中断优先级管理NVIC
STM32学习总结(二)——GPIO
The selection points you need to know about the helmet identification system
Use regex to verify whether the file name is legal
小程序技术原理分析
自定义形状seekbar学习
LAGRANGIAN FLUID SIMULATION WITH CONTINUOUS CONVOLUTIONS
华为IOT平台温度过高时自动关闭设备场景试用
Robust 3D Object Detection in Cold Weather Conditions
随机推荐
需求文档(PRD)撰写指南
AI-based intelligent image recognition: 4 different industry applications
如何快速转行做产品经理
CKEditor富文本编辑器工具栏自定义笔记
使用ActiveReports制作第一张报表
我心仪的数据集—目标检测为主
Mei cole studios - deep learning second BP neural network
NUC980-镜像烧录
Maykle Studio - HarmonyOS Application Development Fourth Training
SWOT分析法
CMT2380F32模块开发2-IDE软件配置
CMT2380F32模块开发3-GPIO例程
安全帽识别系统-为安全生产保驾护航
win10 配置tensorflow(GPU) anaconda3 cuda9.0 cudnn for 9.0
梅科尔工作室-DjangoWeb 应用框架+MySQL数据库第五次培训
vmware不可恢复错误vmui
梅科尔工作室-Pr第一次培训笔记(安装及项目创建)
vscode插件开发——代码提示、代码补全、代码分析(续)
Node-3.构建Web应用(二)
Maykle Studio - HarmonyOS Application Development Third Training