当前位置:网站首页>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
边栏推荐
- Mongodb basic knowledge summary
- 集合详解之 Collection + 面试题
- 04. Project blog log
- Talking about the type and function of lens filter
- Improve jpopup to realize dynamic control disable
- 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
- MySQL if and ifnull use
- Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
- JS quick start (II)
- Sliding window problem review
猜你喜欢
随机推荐
组播和广播的知识点梳理
Tetris
[effective Objective-C] - memory management
2022 half year summary
Implementing fuzzy query with dataframe
改善Jpopup以实现动态控制disable
Cuda11.1 online installation
Sliding window problem review
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Nacos - TC Construction of High available seata (02)
Talking about the type and function of lens filter
EditorUtility.SetDirty在Untiy中的作用以及应用
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
Vulhub vulnerability recurrence 71_ Unomi
Unity gets the width and height of Sprite
【LeetCode】18、四数之和
First acquaintance with CDN
C# AES对字符串进行加密
Cve-2019-11043 (PHP Remote Code Execution Vulnerability)