当前位置:网站首页>Es7/es9 -- new features and regularities

Es7/es9 -- new features and regularities

2022-06-25 23:03:00 Climbing procedural ape

ES7 New characteristics

Check whether the array contains an element includes 2**10 2 Of 10 Power

			let array = [' A dream of red mansions ',' Journey to the west ',' The romance of The Three Kingdoms ',' Water margin ']

            console.log(array.includes(' A dream of red mansions ')) // true
            console.log(array.indexOf(' A dream of red mansions ')) // 0

            console.log(2**10) // 1024 2 Of 10 Power 

ES9 Regular extension

(1) Regular grouping

As shown in the figure below , You can see the obvious regular grouping , And you can rename the matching value , Use attributes to get , When regular changes are prevented , The problem of digital position change

			let str = '<a href="http://www.atguigu.com"> Silicon Valley </a>'
            console.log(str)
			const REG = /<a href="(?<url>.*)">(?<text>.*)<\/a>/  //  Single quotation marks are not allowed here ,?<name> Is to rename the matched value 

			let result = REG.exec(str)

            console.log(result)
            console.log(result.groups.url)

(2) Reverse and forward assertions

Adding conditions , You can judge what is ahead or what is behind , Prevent matching to multiple  

(3)dotAll

characteristic :. It's metacharacter , Any single character other than the newline character ,ES9 Added /s Can match any character , Add one at the end of the regular /s that will do

ES10 --  Object extension methods

Objects and Map Interchangeability of

 ES10 --  A string of trimStart() And trimEnd()

let str = `  ilove you
   and you   `;
         console.log(str.trimStart()) // Remove the initial blank 
         console.log(str.trimEnd()) //  Remove the blanks at the end 

ES10  -- flat And flatMap

flat You can convert multidimensional arrays into one-dimensional arrays , The number inside is the depth of conversion  

ES11 --  Private property

Use # Mark the private attribute , Private properties can be manipulated inside a class , It is not allowed outside the class

 ES11  -- String Of mathAll  Match all

for (let v for result){

        // To extract in bulk

}

ES11 --  Optional chain operator ?.

config&&config.db&&config.db.host, First judge config Whether there is , And then determine config Medium db Whether there is , And then I got it host, I could just write it as config?.db?.host

ES11 --  dynamic import

Import again when using , Load faster

btn.onclick = function () {
    import('./m1.js').then(module => {
        module.hello();
    })
}

ES11 -- BigInt type   Big integer , Add a after the number n that will do

Larger number operations , It supports integers of any length , Cannot operate with ordinary values , The result of the operation is the same BigInt

let n = 521n;
let m = BigInt(521)

ES11 --  Absolute global object gloalThis, Point to windows object

原网站

版权声明
本文为[Climbing procedural ape]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251913429303.html

随机推荐