当前位置:网站首页>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
边栏推荐
- io. seata. common. exception. FrameworkException: can not connect to services-server.
- Mysql database (28): Variables
- 合理地配置线程池
- [image denoising] image denoising based on regularization with matlab code
- A fruitful afternoon
- Redis中的事务
- "As a service", the future has come, starting from the present | new mode of it consumption, FOD billing on demand
- Can't understand kotlin source code? Starting with the contracts function~
- Wireshark basic commands
- What are meta-inf and WEB-INF respectively?
猜你喜欢

5G R17标准冻结,主要讲了些啥?

基於分布式數據庫本身的定時備份方法
![leetcode:5270. Minimum path cost in Grid [simple level DP]](/img/c5/37fd1878e92f95340926e0ea75f150.png)
leetcode:5270. Minimum path cost in Grid [simple level DP]

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

DACOM G150 dual-mode earphones make sound for love and protect the healthy growth of children's hearing

Hardware test - why not use grounding clip for ripple test

Shell arrays and functions
![leetcode:5259. Calculate the total tax payable [simple simulation + see which range]](/img/f4/e6329c297dbe668e70f5e37bfc2852.png)
leetcode:5259. Calculate the total tax payable [simple simulation + see which range]

RT thread simulator builds lvgl development and debugging environment

负数取余问题
随机推荐
RHCA回忆录---CL280介绍
[image denoising] image denoising based on anisotropic filtering with matlab code
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
leetcode:6094. Company name [group enumeration + cannot repeat set intersection + product Cartesian product (repeat indicates length)]
In 2021, the global revenue of electro-optical modulator (EOM) is about USD 360.3 million, and it is expected to reach USD 704.4 million in 2028
DACOM G150 dual-mode earphones make sound for love and protect the healthy growth of children's hearing
“即服务”,未来已来,始于现在 | IT消费新模式,FOD按需计费
CVPR 2022 oral Dalian Institute of technology proposed SCI: a fast and powerful low light image enhancement method
模块八作业
Standard library template learning introduction original
Equipment management - borrowing and returning module 1
Php+flash large file breakpoint continuation function sharing
Rhca memoirs -- Introduction to cl280
RT thread simulator builds lvgl development and debugging environment
easycode一键生成插件自定义模板
MySQL数据库实验一 数据定义
基于微信电子书阅读小程序毕业设计毕设作品(2)小程序功能
Uniapp uses the Ali Icon
攻防世界(web篇)---supersqli
存储体系概述