当前位置:网站首页>Promise to solve hell function calls can be used infinitely
Promise to solve hell function calls can be used infinitely
2022-06-12 19:29:00 【laoli815】
js promise The returned result is still promise As long as you want to keep adjusting
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcdn.net/ajax/libs/es6-promise/4.2.8/es6-promise.auto.js"></script>
</head>
<body>
<script> let l1=[1,2,3,4] console.log(l1[2]) const p=new Promise((resolve,reject)=>{
reject(" Rejected brother, next time try ") }) const p2=new Promise((resolve,reject)=>{
resolve(" I succeeded in ") }) Promise.all([p,p2]).then(res=>{
console.log("p,p2 All have been carried out ") }).catch(err=>{
console.log("p,p2 One failed to execute ",err) }) console.log(p) console.dir(p) const t=p.then(res=>{
console.log(res," I love Beijing Tian'an incisors ") }).catch(rej=>{
console.log(" The rejected content is ",rej) }) .then(res=>{
console.log(" Xiao Ming is a good boy ") }).then(res=>{
console.log(" Wang Dana's country love is beautiful. I like it ") return Promise.reject(" Is to refuse you ") }) console.log(t) console.dir(t) f=t.then(res=>{
console.log(" Well, yes, it was rejected ") }).catch(err=>{
console.log(err," The boy was rejected ") }) console.log(f) console.dir(f) f.then(res=>{
console.log(" I am so sad that I have been lovelorn ") }).catch(err=>{
console.log(" Xiao Ming likes to go to the gym ") }).then(res=>{
console.log(" Just like you ") }) </script>
</body>
</html>
Execution results 
promise.then and catch All the returned values of are promise, With or without return It can be accessed continuously , But it should be noted that only when promise The state of is rejected It will call catch Of course, if promise If there is an error code in the execution body, it will also execute , When the state is fulfilled It will call then, therefore catch If the statement is executed correctly , Still call then Method
But there's a question console.log(t) console.dir(t) Why do you put it in front of you and execute it in advance , state pending I can still understand , however fulfilled Why not , You can tell me what you know in the comment area. Thank you
边栏推荐
- 基于微信电子书阅读小程序毕业设计毕设作品(2)小程序功能
- Dacom G150双模耳机,为爱发声,呵护孩子听力健康成长
- 存储体系概述
- Research Report on global and Chinese cosmetics industry market sales scale forecast and investment opportunities 2022-2028
- IO流基础知识详解--文件及IO流原理
- Mysql database (28): Variables
- mysql的增删改查,mysql常用命令
- Redis (XXXII) - using redis as a distributed lock
- META-INF、WEB-INF分别是什么?
- Market development planning and investment prospect analysis report of Chinese government investment and financing platform 2022-2027
猜你喜欢

What is data driven
![leetcode:5289. Distribute cookies fairly [see data range + DFS pruning]](/img/be/820bfb3aaf23a397e65f96693770f2.png)
leetcode:5289. Distribute cookies fairly [see data range + DFS pruning]

嵌入式开发:固件工程师的6项必备技能

基於分布式數據庫本身的定時備份方法

A fruitful afternoon

IO流基础知识详解--文件及IO流原理

负数取余问题

In 2021, the global revenue of chlorinated polyvinyl chloride (CPVC) was about $1809.9 million, and it is expected to reach $3691.5 million in 2028

vc hacon 聯合編程 GenImage3Extern WriteImage

基于微信电子书阅读小程序毕业设计毕设作品(3)后台功能
随机推荐
The Bean Validation API is on the classpath but no implementation could be found
原生Servlet - 文件的Upload&Download
今晚7:00 | PhD Debate 自监督学习在推荐系统中的应用
Implementation of VGA protocol based on FPGA
美团获得小样本学习榜单FewCLUE第一!Prompt Learning+自训练实战
Chrome browser solves cross domain problems
基于微信电子书阅读小程序毕业设计毕设作品(6)开题答辩PPT
Equipment management - borrowing and returning module 1
【图像去噪】基于各向异性滤波实现图像去噪附matlab代码
CVPR 2022 oral Dalian Institute of technology proposed SCI: a fast and powerful low light image enhancement method
设备管理-借还模块1
PHP converts total seconds to hours, minutes and seconds
The solution of BiliBili video list name too long and incomplete display
攻防世界(web篇)---supersqli
API call display, detailed API of Taobao, tmall and pinduoduo commodity pages, and return of APP side original data parameters
leetcode:5289. Distribute cookies fairly [see data range + DFS pruning]
5g R17 standard is frozen. What does it say?
Attack and defense world (WEB) -- supersqli
【数字IC/FPGA】数据累加输出
设备管理-借还模块界面代码