JavaScript reinforcement tutorial-javascript Performance Optimization

Source: Internet
Author: User
The location of data access also affects the speed of JavaScript operations. Let's summarize the most reasonable location for data access allocation, the access location that can efficiently run JavaScript data also affects the speed of JavaScript operations. Let's summarize the most reasonable access location allocation and the ability to efficiently run JavaScript
The Data Access location is divided into 1. literal (such as true, false, null, etc.) 2. local variable (var a = 5;) 3. array element (var arr = []; arr [0] = 5;) 4. object Member
All of the above can store data.
According to the time required for reading data 200 times in different browsers, the speed is from 1 2 3 4 to 1 2 3 4 (according to the conclusion, different browsers will fluctuate)

Summary of quick and efficient JavaScript code execution:
1. The access literal volume and local variables are faster than the array elements and object members.
2. Because local variables are at the starting position of the scope chain, accessing local variables is faster than accessing cross-domain variables. The deeper the variable's location in the scope chain, the slower the access speed. Because the global variables are always at the end of the scope chain, the slowest access speed.
3. nested object members will significantly affect performance and should be used as little as possible.
4. The deeper the location of an attribute or method in the prototype chain, the slower the access speed.
5. Generally, you can save array elements, object members, and cross-domain variables in local variables to improve JavaScript performance, because accessing local variables is faster.
6. Use with as little as possible because it will change the execution environment scope chain. Similarly, the substatement catch in the type-catch statement has the same effect, so be careful.
With the above release, you can significantly improve the actual performance of Web applications that use a large number of JavaScript applications.

The above is the content of the JavaScript enhancement tutorial-javascript performance optimization. For more information, see PHP Chinese website (www.php1.cn )!

Related Article

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.