当前位置:网站首页>Promise summary
Promise summary
2022-07-06 05:24:00 【I can't download the software when I'm ready】
promise It is an important knowledge point in the front end , Here's a brief summary .
First of all promise Implementation form , The grammatical structure is
const Variable =new Promise((resolve,reject)=>{
resolve() // A successful call resolve
reject() // Failed call reject
})
Variable .then((value)=>{
The result you want when you succeed
},(reason)=>{
The result you want when you fail
})
Give me an example :
Now write a story about promise Example , It is required to customize a number , When the number is greater than 30 When , It outputs “ I'm sorry ”, When the number is less than 30 I'll output congratulations when you !
const pro=new Promise((resovle,reject)=>{
let n=98
if(n<=30){
resovle(n)
}else{
reject(n)
}
})
pro.then((value)=>{
alert(" congratulations !!!"+value)
},(reason)=>{
alert(" I'm sorry !!"+reason)
})
Because when defining numbers 98, Greater than 30, So the output is sorry
边栏推荐
猜你喜欢
js Array 列表 实战使用总结
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[leetcode] 18. Sum of four numbers
初识CDN
F12 solve the problem that web pages cannot be copied
GAMES202-WebGL中shader的編譯和連接(了解向)
Imperial cms7.5 imitation "D9 download station" software application download website source code
TCP three handshakes you need to know
Vulhub vulnerability recurrence 68_ ThinkPHP
C进阶-数据的存储(上)
随机推荐
Vulhub vulnerability recurrence 67_ Supervisor
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
浅谈镜头滤镜的类型及作用
Talking about the type and function of lens filter
[cloud native] 3.1 kubernetes platform installation kubespher
HAC cluster modifying administrator user password
SQLite add index
Cuda11.1 online installation
First acquaintance with CDN
UCF(2022暑期团队赛一)
Sliding window problem review
Microblogging hot search stock selection strategy
Please wait while Jenkins is getting ready to work
Questions d'examen écrit classiques du pointeur
Nacos - TC Construction of High available seata (02)
Can the feelings of Xi'an version of "Coca Cola" and Bingfeng beverage rush for IPO continue?
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Class inheritance in yyds dry inventory C
GAMES202-WebGL中shader的编译和连接(了解向)