当前位置:网站首页>Advanced application of ES6 modular and asynchronous programming
Advanced application of ES6 modular and asynchronous programming
2022-07-01 04:25:00 【Roydly】
Basic use
1~ Default export syntax :export default Default export member
2~ Default import Syntax :import Receive name from ' Module name '
3~ matters needing attention
1- Can only be used once per module export default, Otherwise, an error will be reported ***
2- When importing a package, add js suffix , Otherwise, it will report a mistake
3- The receiving name can be arbitrarily selected , But it should be legal , Cannot start with a number
4~ Export... On demand
grammar :export let xx='xxx'
export function xx(){}
xport default You can add the default export
5~ Import on demand
grammar :import {xx}from ' Module name '
xx The name of must be consistent with the imported name {xx,xx as Change the name }
import info ,{xx,xx} from ' Module name ' Import is used with default import
info Contains the contents exported by default log Print info that will do
6~ Directly import and execute the code in the module
direct :import 'xxx.js' Path to module name
Promise
1- Back to hell
Code coupling is too strong Pull a body , Difficult to maintain
A lot of redundant code is nested with each other , Poor readability
2-Promise The basic concept of
① Promise It's a constructor
We can create Promise Example const p = new Promise()
new Coming out Promise Instance object , Represents an asynchronous operation
② Promise.prototype Contains a .then() Method
every time new Promise() The instance object obtained by the constructor ,
Can be accessed through the prototype chain .then() Method , for example p.then()
③ .then() Method is used to specify success and failure callback functions in advance
p.then( Successful callback function , Failed callback function )
p.then(result => { }, error => { })
call .then() When the method is used , Successful callback function is required 、 The failed callback function is optional
7-then-fs Basic use of
install then-fs
call then-fs Provided readFile() Method , You can read the contents of the file asynchronously , Its return value is Promise Instance object of . because This can call .then() Method for each Promise Asynchronous operation specifies the return after success and failure Tonal function
8-async/await --
async function getAllFile() {
console.log('B')
const r1 = await thenFs.readFile('./files/1.txt', 'utf8')
console.log(r1)
const r2 = await thenFs.readFile('./files/2.txt', 'utf8')
console.log(r2)
const r3 = await thenFs.readFile('./files/3.txt', 'utf8')
console.log(r3)
console.log('D')
}
9- Macro task
setTimeout、setInterval、
asynchronous Ajax request 、
File operations
Other macro tasks
10- Micro task
Promise.then、.catch and .finally
process.nextTick
Other micro tasks
11- priority
After each macro task is executed , Will check whether there are micro tasks to be executed ,
If there is , After all micro tasks are executed , Continue to the next macro task
priority Sync --》 Micro task ----》 Macro task
边栏推荐
- 嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
- Analyse et cas du modèle pageobject
- Concurrent mode of different performance testing tools
- 25.k sets of flipped linked lists
- Mallbook: how can hotel enterprises break the situation in the post epidemic era?
- Embedded System Development Notes 81: Using Dialog component to design prompt dialog box
- 京东智能客服言犀意图体系搭建和意图识别技术介绍
- Embedded System Development Notes 79: why should I get the IP address of the local network card
- Internet winter, how to spend three months to make a comeback
- Odeint and GPU
猜你喜欢

“目标检测“+“视觉理解“实现对输入图像的理解

Ten wastes of software research and development: the other side of research and development efficiency

Huawei simulator ENSP - hcip - Hybrid Experiment 2

基于Unet的环路滤波

2022年上海市安全员C证考试题模拟考试题库及答案

ThreeJS开篇

Unity之三维空间多点箭头导航

NFT: start NFT royalty journey with eip-2981

Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security

2022年T电梯修理题库及模拟考试
随机推荐
LeetCode 1380. Lucky number in matrix
OSPF notes [multiple access, two multicast addresses with OSPF]
Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
2022年聚合工艺考试题及模拟考试
JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
[human version] Web3 privacy game in the dark forest
使用scroll-view实现滑块视图可能遇到的问题及其解决方法
Recommend the best product development process in the Internet industry!
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
Web server: how to choose a good web server these five aspects should be paid attention to
总结全了,低代码还需要解决这4点问题
OdeInt與GPU
Embedded System Development Notes 79: why should I get the IP address of the local network card
Spock单元测试框架介绍及在美团优选的实践___第一章
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
25.k sets of flipped linked lists
slf4j 简单实现
一些小知识点
Offline installation of Wireshark 2.6.10