"The essence of javascript Language" Reading Notes 4: the essence of javascript Language

Source: Internet
Author: User

"The essence of javascript Language" Reading Notes 4: the essence of javascript Language
Chapter 7 Regular Expressions

A regular expression is the most powerful character to process strings.
Through the regular expression, we can easily perform various operations on the string. Here we will not summarize this chapter, and then make a special summary of the regular expression.

Chapter 8 Method

The '+' operator is optimized much in a newer browser, which is much faster than the array. join function.

Array

Array. concat and Array. slice functions can generate new arrays.

The Array. shift function is usually faster than the pop function.

In the Array. sort callback function, Array elements are compared as strings by default. Similarly, this method is unstable (the method stability varies with different browsers) and uses sort (). sort (), such chained operations cannot obtain stable sorting. Therefore, you should avoid using the sort function for chained operations.

The Array. unshift method returns the length of the new Array, while the ie6 browser always returns undefined because of an error in the implementation of the unshift function.

Number

The difference between the number. toFixed method and the number. toPrecision method is that the value of the parameter supported by the toFixed method ranges from 0 ~ 20, while the range of parameters supported by the toPrecision function is 0 ~ 21.

Number. The parameter of the toString function represents the hexadecimal value. The default value is 10. You can set it to any number. Of course, it is usually set to an integer. This method can be used to generate a random number, for exampleMath.random().toString(36).substr(3)To generate a random number.

Regexp

Although the regExp.exe c method is powerful, it is also the slowest function. It uses forward matching technology to continuously rescan scanned strings. When there is a g modifier, its performance will be further reduced.

The regexp. text method is simple, but it is the fastest function. Do not use g ID for it because it is useless.

String

String. the match method matches a regular expression. If the expression is not identified by g, its effect is equal to regexp. test is the same. If it has a g ID, it generates (Outside the capture group.

If the string. replace method has a special meaning when the second parameter is a string, the character $ is as follows:

Dollar string Sequence Replacement object
$ $ Escape Character
$ & Entire matched text
$ Number Text captured by group
$' Match previous text
$' Matched text

When the second parameter is a function, its parameter is ($&, $1……$9.

The string. split method has the second parameter, which is used to limit the size of the returned array. When the first parameter is a regular expression, the text captured by the group is included in the split array. At the same time,The browser before ie8 will exclude null strings from the output Array.

String. toLocalLowerCase, mainly used in Turkish, because in Turkish, 'I' is escaped as 'l' rather than I.

Chapter 9 code style

A good program has a forward-looking structure that will repeat the modifications that may be needed in the future without making it an excessive burden.

Note that{Put it at the end of a row rather than the beginning of the next line, because it will avoid a terrible design error in the return Statement of js.

Try to keep the comments updated, and the comments with errors are even worse than those without comments.

When the program cannot describe itself, you need to write comments. comments must be meaningful, and the obvious code does not need to be annotated.

More line comments should be used in the Code. Block comments are often used for formal document record and comments.

For script applications and tool libraries, I only use one unique global variable. Each object has its own namespace to facilitate code management.

For more encoding styles, see section 5

The last part of this book will end in the fifth part. The fifth part will summarize what the author considers as a beautiful feature, as well as cancer and dregs. At the same time, it will give a personal summary of javascript Code compiling standard ppt.

For more information, see the zakwu website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.