What are the new features of V8 8.5
This article focuses on "what are the new features of V8 8.5". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn what are the new features of V8 8.5.
Promise.any
Promise adds an any method that receives an array of Promise, and when one of the Promise in the array is fulfilled, the Promise it returns is returned.
Const promises = [fetch ('/ endpoint-a'). Then (() = >'a'), fetch ('/ endpoint-b'). Then (()) = >'b'), fetch ('/ endpoint-c'). Then (() = >'c'),]; try {const first = await Promise.any (promises); / / any Promise is fulfilled status console.log (first) / / → 'b'} catch (error) {/ / all Promise are rejected console.assert (error instanceof AggregateError); / / reject result array console.log (error.errors);}
If all input Promise is rejected, Promise.any will return an exception of type AggregateError, and the errors property of this object contains all Promise rejected properties.
Be careful not to be confused with the Promise.race method, the race method is that any Promise in the array is resolved or rejected, while the any method must be resolved, and an exception is thrown if all are rejected.
String.prototype.replaceAll
String.prototype.replaceAll provides an easy way to replace all matches of substrings without having to create a global RegExp.
Look at the following example. In the past, to replace all the + in queryString, you need to create a global regular:
Const queryString = 'qroomqueryqualified parameters; queryString.replace (/\ + / g,'')
Now you just need to use the replaceAll method:
QueryString.replaceAll ('+','')
Logical assignment operator
The logical assignment operator is a new compound assignment operator, which can take the logical operation & &, | or? Combined with the assignment operation into a single command.
X & & = y; / / equivalent to x & & (x = y) x | | = y; / / equivalent to x | (x = y) x? = y; / equivalent to x? (X = y) at this point, I believe you have a deeper understanding of "what are the new features of V8 8.5". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!