当前位置:网站首页>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)
边栏推荐
- 集群、分布式、微服務的區別和介紹
- Mysql database learning (7) -- a brief introduction to pymysql
- 拼多多新店如何获取免费流量,需要从哪些环节去优化,才能有效提升店内免费流量
- 4. 对象映射 - Mapping.Mapster
- Leakage relay jelr-250fg
- 论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
- JVM (XX) -- performance monitoring and tuning (I) -- Overview
- 拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
- 说一说MVCC多版本并发控制器?
- 漏电继电器LLJ-100FS
猜你喜欢
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
1.AVL树:左右旋-bite
Jhok-zbg2 leakage relay
SAP webservice 测试出现404 Not found Service cannot be reached
高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
Flink SQL realizes reading and writing redis and dynamically generates hset key
DOM-节点对象+时间节点 综合案例
[paper reading] semi supervised left atrium segmentation with mutual consistency training
Leakage relay llj-100fs
Unity让摄像机一直跟随在玩家后上方
随机推荐
Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
常用消息队列有哪些?
Egr-20uscm ground fault relay
CVE-2021-3156 漏洞复现笔记
Preliminary practice of niuke.com (9)
How does mapbox switch markup languages?
Two person game based on bevy game engine and FPGA
Lombok plug-in
JVM(二十) -- 性能监控与调优(一) -- 概述
[JS component] date display.
As we media, what websites are there to download video clips for free?
Paper reading [semantic tag enlarged xlnv model for video captioning]
论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Cve-2021-3156 vulnerability recurrence notes
sql查询:将下一行减去上一行,并做相应的计算
[binary tree] binary tree path finding
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
Mysql database learning (7) -- a brief introduction to pymysql
Jhok-zbl1 leakage relay