当前位置:网站首页>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 ,
Promise
An error thrown internally , It doesn't react to the outside - When in
pending
In 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
边栏推荐
- [database] MySQL basic operation (basic operation ~)
- Detailed explanation of the differences between TCP and UDP
- Innovation training (10)
- Unity攝像頭跟隨鼠標旋轉
- [WinUI3]编写一个仿Explorer文件管理器
- The programmer starts the required application with one click of window bat
- js 判斷數字字符串中是否含有字符
- leetcode001--返回和为target的数组元素的下标
- Leetcode - > 1 sum of two numbers
- The unity camera rotates with the mouse
猜你喜欢
Pixel mobile phone brick rescue tutorial
View analysis of scenic spots in ArcGIS
Spark small case - RDD, spark SQL
[winui3] write an imitation Explorer file manager
Learning Android from scratch -- Introduction
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
C language: Advanced pointer
Perfect test of coil in wireless charging system with LCR meter
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
COM in wine (2) -- basic code analysis
随机推荐
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
CLion+OpenCV identify ID number - detect ID number
[2021] Spatio-Temporal Graph Contrastive Learning
Druid -- JDBC tool class case
Opencv + clion face recognition + face model training
[database] MySQL single table query
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
Leetcode009 -- search the target value in the array with binary search
Leetcode - > 1 sum of two numbers
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
js 判断数字字符串中是否含有字符
Simply drag objects to the item bar
Learning Android II from scratch - activity
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
AQS源码阅读
Record the ThreadPoolExecutor main thread waiting for sub threads
leetcode002--将有符号整数的数字部分反转
MySQL -- execution process and principle of a statement
Jetpack -- lifecycle usage and source code analysis
Detailed explanation of the differences between TCP and UDP