当前位置:网站首页>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
边栏推荐
- Leetcode001 -- returns the subscript of the array element whose sum is target
- leetcode002--将有符号整数的数字部分反转
- Code007 -- determine whether the string in parentheses matches
- Wine (COM) - basic concept
- Innovation training (10)
- Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
- Perfect test of coil in wireless charging system with LCR meter
- 跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
- Innovation training (XI) airline ticket crawling company information
- List remove an element
猜你喜欢
Small volume Schottky diode compatible with nsr20f30nxt5g
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)
/etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
Eight misunderstandings that should be avoided in data visualization
Introduction to raspberry pie 3B - system installation
Innovative practice of short video content understanding and generation technology in meituan
Thoughts on a small program
Sword finger offer: the path with a certain value in the binary tree (backtracking)
Installation and deployment of Flink and wordcount test
[2021] Spatio-Temporal Graph Contrastive Learning
随机推荐
Unity RawImage背景无缝连接移动
MySQL -- execution process and principle of a statement
Leetcode001 -- returns the subscript of the array element whose sum is target
【数据库】MySQL基本操作(基操~)
unity摄像机旋转带有滑动效果(自转)
Unity rawimage background seamlessly connected mobile
Innovation training (XI) airline ticket crawling company information
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
[winui3] write an imitation Explorer file manager
The last day of 2021 is the year of harvest.
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
Teach you how to build the ruoyi system by Tencent cloud
MySQL time function query
Case of using stream load to write data to Doris
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)
Manually write smart pointer shared_ PTR function
Analysis of POM files
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
Com alibaba. Common methods of fastjson
Leetcode009 -- search the target value in the array with binary search