当前位置:网站首页>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
边栏推荐
- Grey correlation cases and codes
- js 图片路径转换base64格式
- What is uid? What is auth? What is a verifier?
- Web server: how to choose a good web server these five aspects should be paid attention to
- [Master / slave] router election in DD message
- 陈宇(Aqua)-安全->云安全->多云安全
- 2022年T电梯修理题库及模拟考试
- Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.2 multiple registration protocol (MRP)
- Internet winter, how to spend three months to make a comeback
- 软件研发的十大浪费:研发效能的另一面
猜你喜欢
【LeetCode】100. Same tree
TASK04|數理統計
京东智能客服言犀意图体系搭建和意图识别技术介绍
Go learning --- unit test subtest
NFT: start NFT royalty journey with eip-2981
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
JS image path conversion Base64 format
Do280 management application deployment --rc
Use winmtr software to simply analyze, track and detect network routing
[deep learning] (4) decoder mechanism in transformer, complete pytoch code attached
随机推荐
Analyse et cas du modèle pageobject
Threejs opening
Use winmtr software to simply analyze, track and detect network routing
尺取法:有效三角形的个数
"Target detection" + "visual understanding" realizes the understanding of the input image
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
Possible problems and solutions of using scroll view to implement slider view
Annual inventory review of Alibaba cloud's observable practices in 2021
Programs and processes, process management, foreground and background processes
Learn Chapter 20 of vue3 (keep alive cache component)
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
What are permissions? What are roles? What are users?
Maixll-Dock 快速上手
MySQL function variable stored procedure
Common thread methods and daemon threads
定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
(12) Somersault cloud case (navigation bar highlights follow)
[untitled] Li Kou 496 Next larger element I
NFT:使用 EIP-2981 开启 NFT 版税之旅
[leetcode skimming] February summary (updating)