This article ish5eduAgency officialHTML5 Trainingtutorials, the main introduction:JavaScript Intensive Tutorials--Data access
the location of data access also affects the speed of JavaScript, so let's summarize the most reasonable and efficient way to run JavaScript if you can allocate access locations .
The data access location is divided into 1. Literals (such as true, false, NULL, and so on) 2. Local variables (var a=5;) 3. Array elements (Var arr=[]; arr[0]=5;) 4. Object Members
all of these can store data
based on the time required to read data 200 000 times in different browsers, from fast to slow to 1 2 3 4 (combined, different browsers will have a float)
quick and efficient execution of JavaScript code summary:
1. Access literals, local variables are faster than array elements and object members.
2. Because local variables are in the starting position of the scope chain, accessing local variables is faster than accessing cross-domain variables. The deeper the variable's position in the scope chain, the slower the access, and the slowest the access because the global variable is always at the end of the scope chain.
3. Nested object members can significantly affect performance and are used sparingly.
4. The deeper the property or method is in the prototype chain, the slower the access speed.
5. In general, you can promote JavaScript performance by storing array elements, object members, and cross-domain variables in local variables, because accessing local variables is faster
6. Use with as little as possible, because he will change the execution of the environment scope chain, the same Type-catch statement in the sub-statement catch also has the same effect, so be careful.
with the above release, you can significantly improve the real-world performance of a large number of Web applications that use JavaScript.
Click to enter JS Intensive tutorial
This article is from the "11721999" blog, please be sure to keep this source http://11731999.blog.51cto.com/11721999/1834187
JavaScript Intensive tutorial--javascript performance optimization