当前位置:网站首页>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
边栏推荐
- Force buckle 1189 Maximum number of "balloons"
- Codeforces Round #804 (Div. 2) Editorial(A-B)
- Huawei od computer test question 2
- Codeforces Round #804 (Div. 2) Editorial(A-B)
- Figure database ongdb release v-1.0.3
- 浅谈镜头滤镜的类型及作用
- Some common skills on unity inspector are generally used for editor extension or others
- 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
- HAC集群修改管理员用户密码
- Implementing fuzzy query with dataframe
猜你喜欢
nacos-高可用seata之TC搭建(02)
Vulhub vulnerability recurrence 71_ Unomi
Cuda11.1 online installation
Simple understanding of interpreters and compilers
Easy to understand I2C protocol
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
[leetcode16] the sum of the nearest three numbers (double pointer)
剑指 Offer II 039. 直方图最大矩形面积
[classic example] binary tree recursive structure classic topic collection @ binary tree
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
随机推荐
Oracle deletes duplicate data, leaving only one
Talking about the type and function of lens filter
Summary of redis basic knowledge points
[untitled]
Some common skills on unity inspector are generally used for editor extension or others
UCF(2022暑期团队赛一)
HAC集群修改管理员用户密码
Quelques conseils communs sur l'inspecteur de l'unit é, généralement pour les extensions d'éditeur ou d'autres
Nacos - TC Construction of High available seata (02)
算法-- 爬楼梯(Kotlin)
Zoom and pan image in Photoshop 2022
[cloud native] 3.1 kubernetes platform installation kubespher
Jvxetable用slot植入j-popup
Solution of QT TCP packet sticking
Collection + interview questions
05. 博客项目之安全
F12 solve the problem that web pages cannot be copied
SQLite queries the maximum value and returns the whole row of data
组播和广播的知识点梳理
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