Reading Notes: in-depth understanding ES6 (b)

Chapter 2 strings and regular expressions

This chapter introduces the ES6 strings and regular expressions in some of the newer (grammatical). Now, I will usually use to develop more refined out of place for everyone to read.

  1. Better Unicode support.

    First talk about the premise, in the string, character string which there are two: one is a coding unit 16 a BMP character representation; other auxiliary plane is represented by the two character encoding unit 32. These two characters are not the same.

    1.1 the normalize () method.

    This method takes an optional string, the string is then converted to the corresponding Unicode standard form which can then be compared strings. To help ensure that the original strings are two 16-bit 32-bit characters and characters can still be compared.

    1.2 regular expression modifiers u

    In fact, this u modifier added, its purpose is to help the character conversion unit from the encoding operation mode character mode, then u modifier with regular expression matching coding unit can be changed to match the original characters. It is even more so with the normalization.

 

  2. Other string changes.

    Inside this section, said several major approach to the relationship between the strings and strings.

    2.1 Includes () method. For identifying the current string contains a certain substring.

    2.2 startsWith () method. As the name suggests, find the string with a substring begins.

    2.3 endsWith () method. Similarly, from the back to find whether to include a sub-string.

    2.4 REPEAT () method. The method accepts a number of parameters of the type, then the method invokes string repeated n times, returns the string.

      E.g:

1 console.log( "hello".repeat(2) ); // "hellohello"

 

 

  3. Other regular expression syntax changes

    3.1 regular expression y modifier.

    The property will be notified lastIndex property search regular expression starts, if no match is successful in the specified location, then stop the match to continue.

    3.2 flags property.

    In ES6 version, add a regular expression flags property, which can be returned modifiers string all applied to the current regular expression.

 

  4. The template literal.

  This is a pair of anti-apostrophe ( ``) this is more interesting, but also a more central point of knowledge. Simple summary, can be divided into three points:

    4.1 using it can realize multi-line output string. The previous time, multi-line strings rely stitching, and then add a line break. With this string of anti-apostrophe can spell out directly after the multi-line strings, and is displayed when multiple lines.

    4.2 using it can realize a placeholder function . Declare a variable, $ {} may then be used to remove the value of this variable. E.g:   

1 let name = "Steven",
2     message = `Hello, ${name}.`;
3 
4 console.log(message); // "Hello, Steven."

     4.3 template tags. This is because usually with not a lot. So, here to tell a simple idea, interested students can find the original book's details and code.

    This template tag is actually doing it? Simply put, it is a function contains the expression of the anti-apostrophe. This function in reverse apostrophe expression as a parameter, then the tag name is the function name of the function.

(End of this section)

    

Guess you like

Origin www.cnblogs.com/zxxsteven/p/11432659.html