当前位置:网站首页>async / await
async / await
2022-07-07 05:39:00 【InfoQ】
async / await
//fn It's an asynchronous function
async function fn() {
// await keyword , This function must have async
const res = await pAjax({ url: './server/a.php', dataType: 'json' })
// When pAjax The request sent did not come back before , res Will not be assigned
// Only after asking to come back , res Will be assigned a value
// If this print comes back before the request , res No results
// If res It turns out , prove : This code has been delayed , Postpone to the later promise After the object is completed
console.log(res)
console.log(' Subsequent code ')
}
fn()
async function fn() {
const res1 = await pAjax({ url: './server/a.php', dataType: 'json' })
console.log(' demand 1: ', res1)
const res2 = await pAjax({ url: './server/b.php', dataType: 'json', data: res1 })
console.log(' demand 2: ', res2)
const res3 = await pAjax({ url: './server/c.php', dataType: 'json', data: res2 })
console.log(' demand 3: ', res3)
}
console.log('start')
fn()
console.log('end') const div = document.querySelector('div')
div.addEventListener('click', async () => {
const res1 = await pAjax({ url: './server/a.php', dataType: 'json' })
console.log(' demand 1: ', res1)
const res2 = await pAjax({ url: './server/b.php', dataType: 'json', data: res1 })
console.log(' demand 2: ', res2)
const res3 = await pAjax({ url: './server/c.php', dataType: 'json', data: res2 })
console.log(' demand 3: ', res3)
})generator function
// When there is an asterisk , fn It's no longer a function
function* fn() {
console.log(' I'm the first paragraph Code ')
yield ' The first paragraph ends '
console.log(' I'm the second paragraph Code ')
yield ' The second paragraph ends '
console.log(' I'm the third paragraph Code ')
return ' The third paragraph ends '
}
// result Namely fn Generate a for iterator
const result = fn()
// for the first time , from fn Execute from the beginning of to the first yield,
// hold yield The latter is treated as a return value
const first = result.next()
console.log(first)
// The second time , From the first time yield Then start to execute to the second yield end
// hold the second yield The latter is treated as a return value
const second = result.next()
console.log(second)
const third = result.next()
console.log(third)const arr = ['hello', 'world', ' Hello ', ' The world ']
const obj = { name: 'jack' }
for (let key in arr) {
console.log(key, arr[key])
}
for (let value of arr) {
console.log(value)
} const s = new Set(['hello', 'world', ' Hello ', ' The world '])
// 1. add to
s.add(true)const s = new Set(['hello', 'world', ' Hello ', ' The world '])
// 2. Delete
s.delete(' The world ')const s = new Set(['hello', 'world', ' Hello ', ' The world '])
// 3. Judge
console.log(s.has(' Hello '))// 6. for of Loop to traverse
for (let value of s) {
console.log(value)
}duplicate removal
const arr = [1, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 2, 1]
const res = [...new Set(arr)]
console.log(res)边栏推荐
- Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
- Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
- Life experience of an update statement
- 说一说MVCC多版本并发控制器?
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- Make web content editable
- Leakage relay jelr-250fg
- What is dependency injection (DI)
- Torch optimizer small parsing
- Jhok-zbl1 leakage relay
猜你喜欢

Dj-zbs2 leakage relay

分布式事务解决方案之TCC

Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface

JVM (XX) -- performance monitoring and tuning (I) -- Overview

Flink SQL 实现读写redis,并动态生成Hset key
![[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation](/img/f6/cd307c03ea723e1fb6a0011b37d3ef.png)
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation

一条 update 语句的生命经历

利用OPNET进行网络仿真时网络层协议(以QoS为例)的使用、配置及注意点

漏电继电器JD1-100

基于NCF的多模块协同实例
随机推荐
照片选择器CollectionView
JVM(十九) -- 字节码与类的加载(四) -- 再谈类的加载器
ssm框架的简单案例
Phenomenon analysis when Autowired annotation is used for list
消息队列:如何确保消息不会丢失
Make web content editable
5阶多项式轨迹
Paper reading [open book video captioning with retrieve copy generate network]
Unity keeps the camera behind and above the player
集群、分布式、微服务的区别和介绍
利用OPNET进行网络指定源组播(SSM)仿真的设计、配置及注意点
Jhok-zbl1 leakage relay
利用OPNET进行网络单播(一服务器多客户端)仿真的设计、配置及注意点
Paper reading [semantic tag enlarged xlnv model for video captioning]
《4》 Form
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
MySQL数据库学习(7) -- pymysql简单介绍
Let f (x) = Σ x^n/n^2, prove that f (x) + F (1-x) + lnxln (1-x) = Σ 1/n^2
Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i