当前位置:网站首页>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
边栏推荐
- C language games (I) -- guessing games
- TCP server communication flow
- "Target detection" + "visual understanding" realizes the understanding of the input image
- CUDA development and debugging tool
- Jenkins automatically cleans up construction history
- TASK04|数理统计
- selenium打开chrome浏览器时弹出设置页面:Mircrosoft Defender 防病毒要重置您的设置
- Class and object finalization
- PgSQL failed to start after installation
- 这可能是你进腾讯最后的机会了..
猜你喜欢

2022 gas examination question bank and online simulation examination

Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I

JMeter学习笔记2-图形界面简单介绍
![[leetcode skimming] February summary (updating)](/img/62/0d0d9f11434e49d33754a2e4f2ea65.jpg)
[leetcode skimming] February summary (updating)

Do280 management application deployment --rc

slf4j 简单实现

JMeter learning notes 2 - brief introduction to graphical interface

定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见

Knowledge supplement: basic usage of redis based on docker

熊市下的Coinbase:亏损、裁员、股价暴跌
随机推荐
674. longest continuous increasing sequence force buckle JS
2022年化工自动化控制仪表操作证考试题库及答案
Rule method: number of effective triangles
有效的 @SuppressWarnings 警告名称
“目标检测“+“视觉理解“实现对输入图像的理解
MySQL winter vacation self-study 2022 12 (5)
Analyse et cas du modèle pageobject
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
Task04 mathematical statistics
JMeter learning notes 2 - brief introduction to graphical interface
采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
Programs and processes, process management, foreground and background processes
Redis (VII) optimization suggestions
[deep learning] (4) decoder mechanism in transformer, complete pytoch code attached
Odeint and GPU
Valid @suppresswarnings warning name
NFT:使用 EIP-2981 開啟 NFT 版稅之旅
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
slf4j 简单实现
Qt开发经验小技巧226-230