120 days of 1200 hours of wisdom in the junior students. NET (vii) about JS performance

Source: Internet
Author: User

1, declare the variable to be assigned the initial value
2, try to avoid declaring global variables, you can reduce the duplicate name of the system
3, when writing a large number of JS code, you will inevitably encounter a naming conflict, which can be simulated by the namespace mode
To avoid conflict.
4, try to avoid the use of global variables, search global variables will be a layer of search for each scope range,
Time-consuming and inefficient.
5, use the impairment cycle or optimize the cycle condition, do not write i<xxx in the cyclic condition. Length, but with a
Variable to replace, I<len. Because each loop performs a calculation Length,var i=0 also gets out.
To.
6, Avoid using eval ("alert ();") SetInterval ("MyFunc ();", 1000) This
Re-parse the code, inefficient!
7, using native methods, such as the built-in join () reverse () use these browsers originally
There are methods, do not write with their own myjoin, such as low performance, native methods are used C or C
+ + Write, high performance
8, use switch as much as possible instead of multiple if else
9. Try to reduce the number of statements.
var fragment=document.createdocumentfragment (); Using document fragmentation,
Avoid updating pages multiple times

120 days of 1200 hours of wisdom in the junior students. NET (vii) about JS performance

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.