当前位置:网站首页>Knowledge points sorting: ES6
Knowledge points sorting: ES6
2022-04-23 04:53:00 【Crazy_ GirlLL】
ES6 New characteristics
- let Variable ,const Constant , There are block-level scopes ,let,const You cannot declare a declared variable repeatedly , No matter what declaration is used (let,const,var),let Declared variables can be reassigned ,const Reassignment is not allowed , therefore ,let It can be declared first and then assigned , however const Must be declared and assigned . One more thing to note :
const What's blocked is the modification of variable binding , Instead of Prevent modification of member values .const a = 1; Right now a An error will be reported if the value is assigned again ;const person = {name:'1'},person.name='2' No mistake. , however person={name:'2'} You're going to report a mistake
- - Arrow function , Inside and outside the function this The direction is consistent
- - Template string , The quotation marks **` ** identification , There can be spaces (let age=10;let str=` Hello , I have already ${age} Year old `)
- - Deconstruct assignment , Arrays can be nested , Can have null value , There can be residual operators
let node = { type: "Identifier", name: "foo" }; let { type, name } = node; console.log(type); // "Identifier" console.log(name); // "foo"let colors = [ "red", "green", "blue" ]; let [ firstColor, secondColor ] = colors; console.log(firstColor); // "red" console.log(secondColor); // "green" - - import Introduction and export Export of
- - ... Unfold , You can expand the values in the array or object , You can also collect multiple values into one variable
- - async,await Synchronous and asynchronous methods
- - promiss grammar
- - set Array weight removal
let arr=[12,43,23,43,68,12];
let item=[...new Set(arr)];
console.log(item);//[12,43,23,68]
special promise encapsulation axios,promise,setTimeout,fn, Macro task and micro task ,
Back to hell
First use ES6 Medium Promise, Promise , It means to promise to return data to you at a certain point in the future .
But if there's a lot of data , Multi dependent case , It will still produce the sense of seeing back to hell , Then it's used es7 Of async,await 了
promise
principle :
- stay Promise Internal , There is a state manager , There are three states :pending、fulfilled、rejected.
- (1) promise Object initialization state is pending.
- (2) When calling resolve( success ), Will be pending => fulfilled.
- (3) When calling reject( Failure ), Will be pending => rejected.
- The thing to remember is to pay attention to promsie state Only by pending => fulfilled/rejected, Once modified, it can't be changed again .
Link to the original text :https://blog.csdn.net/HannaLh/article/details/106151149
characteristic :
- promise It's an object , The difference between object and function is that object can save state , Function can't ( Except closures ) Once the status changes , It won't change , You can get that at any time
- The state of the object is not affected by the outside world , Only pending,fulfilled,rejected Three states
- Code style. , Easy to understand , Easy to maintain
- Multiple asynchronous wait merges for easy resolution
shortcoming :
- Can't cancel
Promise, Once it's created, it's executed immediately , Unable to cancel - If you do not set the callback function ,
PromiseAn error thrown internally , It doesn't react to the outside - When in
pendingIn the state of , It is impossible to know at what stage ( Just started or almost finished ).
Promise There are three states :pending/reslove/reject .pending It's just pending ,resolve It can be understood as success ,reject It can be understood as a refusal .
meanwhile Promise Three common methods
- then Indicates that the data status after successful asynchronous execution changes to reslove
- catch Indicates that the data status of execution after asynchronous failure changes to reject
- all It means putting multiple unrelated Promise Encapsulate into a Promise Object use then Returns an array of data .
- resolve Successful callback
- reject Failed callback
Promise.all() Batch execution
Promise.all([p1, p2, p3]) Used to transfer multiple promise example , Pack into a new one Promise example , The returned instance is normal promise
It takes an array as an argument
The array can be Promise object , It could be something else , Only Promise Will wait for the state to change
When all the children Promise It's all done , The Promise complete , The return value is an array of all values
There is any failure , The Promise Failure , The return value is the first failed child Promise result
Promse.race
Promse.race That's what running means , That is to say ,Promise.race([p1, p2, p3]) Which of the results is fast , Just go back to that result , Whether the result itself is a success state or a failure state .
Promise.allSettled()
When Promise We can get each one after all the processing Promise The state of , Whether it's handled successfully or not .
Quoted above :https://segmentfault.com/a/1190000020034361
Mr. Ruan Yifeng :https://es6.ruanyifeng.com/#docs/promise
Event cycle mechanism ,promise Use ,
版权声明
本文为[Crazy_ GirlLL]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220554364996.html
边栏推荐
- C language: spoof games
- Recommended scheme for national production of electronic components for wireless charging
- List< Map> Replication: light copy and deep copy
- unity摄像机旋转带有滑动效果(自转)
- Leetcode -- heuristic search
- Detailed explanation of the differences between TCP and UDP
- 泰克示波器DPO3054自校准SPC失败维修
- Innovation training (IX) integration
- Spark small case - RDD, broadcast
- 用LCR表完美测试无线充电系统中的线圈
猜你喜欢

COM in wine (2) -- basic code analysis

泰克示波器DPO3054自校准SPC失败维修

Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)

Learning Android V from scratch - UI

Simply drag objects to the item bar

Teach you how to build the ruoyi system by Tencent cloud

What is a data island? Why is there still a data island in 2022?

MySQL -- execution process and principle of a statement

Innovation training (IV) preliminary preparation - server

Arduino UNO r3+LCD1602+DHT11
随机推荐
Analysis of POM files
Recommended scheme for national production of electronic components for wireless charging
JS generates a specified number of characters according to some words
Unity RawImage背景无缝连接移动
Innovation training (V) configuration information
Innovation training (V) mid term inspection
PIP3 installation requests Library - the most complete pit sorting
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
General enumeration constant class
Flink case - Kafka, MySQL source
[WinUI3]編寫一個仿Explorer文件管理器
The programmer starts the required application with one click of window bat
leetcode——启发式搜索
redis数据类型有哪些
redis和mysql区别
Thoughts on a small program
PHP+MySQL 制作留言板
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Spark optimization
Better way to read configuration files than properties