Compiled JavaScript code

Source: Internet
Author: User

CompileProgramThe key is that the program is written to people, not to computers. If you can understand that others may read your JavaScript, you will write more clearly.Code. The clearer the code, the more difficult it is to make mistakes. Clever code is cute, but this clever code will produce errors. The best rule of thumb is kiss, that is, keep it simple and Sweetie (keep simple and cute ). Another helpful technique is to make comments before writing code. This forces you to think about it first. Once a comment is written, you can write the code below it.
The following is an example of writing a function using this method:
Step 1: write comments
Step 2: Fill in the code
This method not only forces you to think before writing code, but also makes the coding process look easier-by dividing tasks into small, easy-to-code parts, your problem does not look like Mount Everest, but like a group of pleasant ups and downs.
Last... End each statement with a semicolon.
Although it is not strictly required, you should develop the habit of ending each statement with a semicolon, which can avoid further code in this line. If you forget the extra points, the next line of good code will suddenly generate an error. Initialize the variable as "Var" unless you have a better reason not to do so. Using "Var" to localize variables can reduce the chance of confusion between one function and another unrelated function.
Now that you know how to code, let's learn how to make

Your JavaScript code runs quickly.>
---------------------------------------------------------
Speed-based JavaScript code optimization
1. Restrict the workload in the cycle
2. Customize the if-then-else statement in the most likely to impossible order
3. Expression for minimizing repeated executions

refer to URL: http://blog.csdn.net/java2000_net/archive/2008/10/10/3046871.aspx

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.