当前位置:网站首页>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

边栏推荐
- Unity Vector3. Use and calculation principle of reflect
- [classic example] binary tree recursive structure classic topic collection @ binary tree
- GAMES202-WebGL中shader的編譯和連接(了解向)
- Self built DNS server, the client opens the web page slowly, the solution
- 用StopWatch 统计代码耗时
- In 2022, we must enter the big factory as soon as possible
- Steady, 35K, byte business data analysis post
- 改善Jpopup以实现动态控制disable
- First acquaintance with CDN
- Three. JS learning - light and shadow (understanding)
猜你喜欢

Excel转换为Lua的配置文件

无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...

Pix2pix: image to image conversion using conditional countermeasure networks

【云原生】3.1 Kubernetes平台安装KubeSpher

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

js Array 列表 实战使用总结

Hyperledger Fabric2. Some basic concepts of X (1)

Huawei equipment is configured with OSPF and BFD linkage

Can the feelings of Xi'an version of "Coca Cola" and Bingfeng beverage rush for IPO continue?

Easy to understand I2C protocol
随机推荐
F12 solve the problem that web pages cannot be copied
Knowledge points of circular structure
[leetcode] 18. Sum of four numbers
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
Nacos TC setup of highly available Seata (02)
Vulhub vulnerability recurrence 69_ Tiki Wiki
【华为机试真题详解】统计射击比赛成绩
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
Configuration file converted from Excel to Lua
Can the feelings of Xi'an version of "Coca Cola" and Bingfeng beverage rush for IPO continue?
Unity Vector3. Use and calculation principle of reflect
JS quick start (II)
Questions d'examen écrit classiques du pointeur
Jvxetable用slot植入j-popup
算法-- 爬楼梯(Kotlin)
Select knowledge points of structure
注释、接续、转义等符号
【LeetCode】18、四数之和
HAC cluster modifying administrator user password
Qt TCP 分包粘包的解决方法