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

边栏推荐
- [leetcode daily question] number of enclaves
- Vulhub vulnerability recurrence 71_ Unomi
- Unity gets the width and height of Sprite
- Self built DNS server, the client opens the web page slowly, the solution
- Some common skills on unity inspector are generally used for editor extension or others
- Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
- A little knowledge of CPU, disk and memory
- Cuda11.1 online installation
- [QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
- Modbus protocol communication exception
猜你喜欢

Questions d'examen écrit classiques du pointeur

Postman Association

【torch】|torch. nn. utils. clip_ grad_ norm_

Vulhub vulnerability recurrence 72_ uWSGI

Pix2pix: image to image conversion using conditional countermeasure networks

Unity Vector3. Use and calculation principle of reflect

Sword finger offer II 039 Maximum rectangular area of histogram

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

Excel转换为Lua的配置文件

Graduation design game mall
随机推荐
Hyperledger Fabric2. Some basic concepts of X (1)
C AES encrypts strings
Codeforces Round #804 (Div. 2) Editorial(A-B)
Compilation and connection of shader in games202 webgl (learn from)
February 12 relativelayout
[leetcode] 18. Sum of four numbers
Easy to understand I2C protocol
[detailed explanation of Huawei machine test] statistics of shooting competition results
Steady, 35K, byte business data analysis post
First acquaintance with CDN
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Three methods of Oracle two table Association update
Yyds dry inventory SSH Remote Connection introduction
Vulhub vulnerability recurrence 67_ Supervisor
Questions d'examen écrit classiques du pointeur
[leetcode16] the sum of the nearest three numbers (double pointer)
UCF (summer team competition II)
02. Develop data storage of blog project
毕业设计游戏商城
關於Unity Inspector上的一些常用技巧,一般用於編輯器擴展或者其他