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 )!