当前位置:网站首页>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
边栏推荐
- 如何看待智慧城市建设中的改变和机遇?
- Knowledge supplement: basic usage of redis based on docker
- This may be your last chance to join Tencent
- Knowledge supplement: redis' basic data types and corresponding commands
- Concurrent mode of different performance testing tools
- selenium打开chrome浏览器时弹出设置页面:Mircrosoft Defender 防病毒要重置您的设置
- slf4j 简单实现
- 【LeetCode】100. Same tree
- NFT:使用 EIP-2981 開啟 NFT 版稅之旅
- 基于Unet的环路滤波
猜你喜欢

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

NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT

This may be your last chance to join Tencent

MySQL advanced -- you will have a new understanding of MySQL

2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers

NFT: start NFT royalty journey with eip-2981

Threejs opening

软件研发的十大浪费:研发效能的另一面

Grey correlation cases and codes

2022年煤气考试题库及在线模拟考试
随机推荐
陈宇(Aqua)-安全->云安全->多云安全
mysql 函数 变量 存储过程
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
[untitled]
2022年化工自动化控制仪表操作证考试题库及答案
MallBook:后疫情时代下,酒店企业如何破局?
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
OdeInt與GPU
[leetcode skimming] February summary (updating)
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
2022年T电梯修理题库及模拟考试
Loop filtering based on Unet
创新界,聚势行 | 2022人大金仓“百城巡展”火热开启
小程序中自定义组件
分账技术赋能农贸市场,重塑交易管理服务效能
Concurrent mode of different performance testing tools
TCP server communication flow
js 图片路径转换base64格式
JMeter learning notes 2 - brief introduction to graphical interface
Seven crimes of counting software R & D Efficiency