Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points commonly used in the new features of ES6

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the new features of ES6 commonly used knowledge points, have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

1. Keyword

The Let keyword works in the same code block as let. It is not possible to assign a value to this variable before let

The Const keyword is a read-only variable, so it needs to be assigned when it is defined.

two。 Deconstruction

Deconstruction of variables

1 >. The array structure can be assigned locally by using [].

For example:

Let [a recital c] = [1 dagger 3]

Let [a,... C] where c can be assigned as an array

2 >. The object structure uses {} to deconstruct the object, which is similar to the array, except that there is an extra attribute, the most important thing is that the object attributes are not in order, but in order.

3. String

1 >. Using for of, you can traverse each character of a string.

2 >. For judging whether it contains characters: include startswith endwith

3 >. Padstart . Wait, replace the completed function.

4 >. String template, you can add variables to the string ${variable}. You can also label it as html.

5 >. Most of the numerical values are the operation of the function, judging whether it is a number, type conversion, etc.

4. Regular pattern

1 >. Two uses

One:Regex r=new Regex ('matching rules', 'decorating')

Two:Regex matching / matching / embellishments

Regex, where I g y is the modifier

2 > whether the sticky property has a modifier

Flags returns matching modifier

3 >. Support for post-line assertions

5. Array

1 >. You can use const [... A2] = A1 is assigned directly, and the interchange of the two variables is also possible.

2 >. Multiple arrays can be merged with []

3 >. Combined with knot deconstruction

For example:

[a,... Rest] = list list is an array

6. Function

1 >. The use of parameter default value, cannot have a parameter with the same name

2 >. Parameter is lazily evaluated, that is, the default value is recalculated each time

3 >. You can still use deconstruction for function assignment (I think it's similar to object deconstruction).

7. Object

Objects in es6 use types similar to the original struct types in C, but the difference is that methods can be used within objects in es6

For example:

Const person= {Name:wl;Birth,CalTime () {console.log ("");} 8.Symbol

1 >. Equivalent to an extra definition keyword to prevent defined variables from being accidentally rewritten and overwritten.

2 >. The main function is to eliminate magic strings (personal understanding: it is a bunch of strings directly, change it into variables to improve the readability of the code)

9. Collection

1 >. Personal understanding: somewhat similar to the collections in java and C #. Just because of the nature of es6, there are some different functions that implement complex operations. Set can be converted into an array for some deconstruction.

Here there is a collection with the prefix weak, (this is the place where things are temporarily stacked, and if you say no, you can't traverse it.)

10.Proxy cooperates with the observer mode of Reflect

Proxy is an intercept operation, and Reflect is a reflection operation. Read variables and modify them.

Proxy monitor changes, intercept operations, and reflect changes values to achieve the simplest observation mode.

11. Promise

As a constructor, you can call back two functions. (personal understanding: it is more useful in cases with two results, and different functions are called in different situations.)

ArrayBuffer is also a constructor, using a variety of function operations, personal feeling in order to regulate the array.

twelve。 Ergodic

The traversal simulates next, moving the pointer to the end. The difference between es6 and the other languages I used before is that when it is finished, it will output undefined and will not directly destroy the program.

Next: function () {return nextIndex < array.length? {value: array [nextIndex++], done: false}: {value: undefined, done: true}; / / increasing nextIndex is to let the subscript add its own operation. 13.Generator

The essence is to record the internal state of the function, asynchronous operation, personal feeling should be used more in multithreading. Single thread did not think of the value of the application. In essence, you can use yield for suspending operations. Instead of using yield, you can directly use * to turn a function into a suspended function.

14.async

In essence, it is an improved operation of Generator, which does not use yield for hold operation, but uses await for this operation. But it is different from Geneator in that Geneator returns the traversal, and it returns the Promise object.

15.Class

For the original js language, the operation of the class encapsulates a lot of things and has certain templates. In order to better read and understand, plus inheritance, it also reduces the writing of repetitive code. And the pattern is strict, which is more normative to the language. It is similar to class in object-oriented languages.

16. Modifier

This is similar to java's comments, but in a different way. I personally understand that java's comments are for the rules of the code and are easy to modify. But in es6, modifiers are essentially functions that are executed at compile time.

17.Moudle

Modularize some statically compiled things and reduce repetitive writing, just like python introduced a variety of libraries, something introduced into some libraries, writing is relatively simple.

Import {stat, exists, readFile} from 'fs';// introduces export {firstName, lastName, year}; / / output Thank you for reading this article carefully. I hope the article "what are the knowledge points commonly used in the new features of ES6" shared by the editor will be helpful to you? at the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report