当前位置:网站首页>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
边栏推荐
- Algorithm -- climbing stairs (kotlin)
- Excel转换为Lua的配置文件
- 2022 half year summary
- 04. Project blog log
- [leetcode16] the sum of the nearest three numbers (double pointer)
- Oracle deletes duplicate data, leaving only one
- Pickle and savez_ Compressed compressed volume comparison
- 用StopWatch 统计代码耗时
- Leetcode dynamic planning day 16
- 浅谈镜头滤镜的类型及作用
猜你喜欢
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Easy to understand I2C protocol
idea一键导包
Pix2pix: image to image conversion using conditional countermeasure networks
Unity Vector3. Use and calculation principle of reflect
Hyperledger Fabric2. Some basic concepts of X (1)
February 12 relativelayout
Fiddler installed the certificate, or prompted that the certificate is invalid
RT thread analysis - object container implementation and function
Codeforces Round #804 (Div. 2) Editorial(A-B)
随机推荐
GAMES202-WebGL中shader的编译和连接(了解向)
Oracle deletes duplicate data, leaving only one
Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
Huawei od computer test question 2
Algorithm -- climbing stairs (kotlin)
Vulhub vulnerability recurrence 69_ Tiki Wiki
Using stopwatch to count code time
【LeetCode】18、四数之和
Jvxetable用slot植入j-popup
Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
Solution of QT TCP packet sticking
[leetcode16] the sum of the nearest three numbers (double pointer)
[cloud native] 3.1 kubernetes platform installation kubespher
Jvxetable implant j-popup with slot
Compilation and connection of shader in games202 webgl (learn from)
A little knowledge of CPU, disk and memory
Codeforces Round #804 (Div. 2) Editorial(A-B)
Force buckle 1189 Maximum number of "balloons"
Microblogging hot search stock selection strategy
Vulhub vulnerability recurrence 67_ Supervisor