Coding specifications for JavaScript programming languages

Source: Internet
Author: User
Tags end functions variables client

Web page Production WEBJX article introduction: for engineers who are familiar with C + + or the Java language, JavaScript is flexible, easy to understand, and relatively loosely formatted for code. It's easy to learn and apply to your own code. Also because of this, JavaScript coding norms are often despised, the development process of tinkering, and eventually evolved into a follow-up maintenance personnel nightmare. Software exists

For engineers who are familiar with C + + or the Java language, JavaScript is flexible, easy to understand, and relatively loosely formatted for code . It's easy to learn and apply to your own code . Also because of this, JavaScript coding norms are often despised, the development process of tinkering, and eventually evolved into a follow-up maintenance personnel nightmare. The long-term value of software is directly proportional to the quality of the code. Coding specifications can help us reduce unnecessary trouble in programming. and JavaScript code is sent directly to the client browser, directly with the customer to meet, the quality of the coding should be more attention.

This paper discusses the problem of coding standard in JavaScript programming, and analyzes the reasons. Expect more WEB developers to focus on JavaScript coding specifications and focus on software PRODUCT quality issues.

Objective

It is believed that many engineers are not unfamiliar with the reference to C + + and Java coding specifications. But when it comes to coding specifications for JavaScript languages, you might be laughing. Isn't JavaScript a very flexible syntax? Variables can be declared at any time, the statement terminator can be not, strings and numbers can be added, and a few more arguments will not error. Yes, when you turn to JavaScript language from the strict syntax of C + + and Java, you will feel free and relaxed a lot. Loose grammar is an important feature of JavaScript. It is flexible and easy to understand, bringing a lot of convenience to developers, but if the writing process is not noticed, the debugging and maintenance costs of the code will increase invisibly.

JavaScript encoding should be sent directly to the client's browser, code specifications are not only the guarantee of code quality, but also affect the long-term reputation of the product. I hope that the specification of JavaScript programming language can also arouse the attention of more friends.

JAVASCRIPT Coding Specification Recommendations

In this paper, in terms of typesetting, naming, declaration, scope, and the use of some special symbols in JavaScript coding process, some suggestions are given according to the summary of individual learning work, and the reasons are analyzed.

JavaScript file references

JavaScript programs should be kept in the. js file, and it needs to be called in HTML to

As you can see from the output in Listing 4, the InF () function takes effect only within the OUTF () function, and the local variable Innera the scope of the internal function. This encoding allows the scope of variables and functions to become clearer.

Statement

For simple statements, it is still necessary to mention the semicolon necessity, while the line has at most one statement. If an assignment statement uses functions and objects to assign values, you may need to span multiple lines, and always remember to add a semicolon at the end of the assignment statement.

This is because in JavaScript, all expressions can be used as statements, and when line breaks are resolved to the end of an expression, a new error may be introduced when irregular wrapping and semicolons are lost.

For compound statements, if, for, while, do, switch, try ... catch and other code bodies, function-defined function bodies, object definitions, etc., need to be placed inside the curly braces ' {} '.

' {' should be at the end of the line, marking the beginning of the code block.

'} ' should be at the beginning of a line, marking the end of a block of code and needing to align with the beginning of the line ' {' to indicate a complete compound statement segment. This can greatly improve the readability of the code , control logic can be clearly demonstrated.

The included code snippet should be indented 4 more spaces.

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] Next page



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.