JavaScript programming Specification

Source: Internet
Author: User

I believe everyone knows that there is a Java programming specification.
,
But few people know that JavaScript also has programming specifications, which was first proposed by Google. Although in engineering practice, we are relatively casual in writing JavaScript
From the perspective of code standardization, no matter which language should have its own programming specifications. Otherwise, after a period of time, I don't even know what the code I wrote means, what's more, let's look at your code.

Although the Code specification remains to be verified, it was launched by Google and still has a certain degree of authority and reliability.

Google JavaScript Style

Now Google has released another tool to help you check whether JavaScript code strictly complies with Google JavaScript Style Guide: Closure Linter
.

Suppose you have the following code:

var x = 10
var y=20;

For (VAR I = 0; I <10; I ++ ){
X + = I;
Y-= I;
}

VaR z = [10, 20,];

X = Y + Z [0]
+ 10;

Assume the file name is fixme. js.
After running gjslint-strict fixme. js on the command line, the following result is displayed:

Line 1, E: 0010: (New error) missing semicolon at end of line
Line 2, E: 0002: missing space before "="
Line 2, E: 0002: missing space after "="
Line 4, E: 0002: missing space before "("
Line 4, E: 0002: missing space after ";" in for statement
Line 4, E: 0001: extra space before ")"
Line 6, E: 0006: (New error) Wrong indentation: expected any of {2} but got 3
Line 9, E: 0121: Illegal comma at end of array literal
Line 12, E: 0120: binary operator shoshould go on previous line "+"
Found 9 errors, including 2 new errors, in 1 files (0 files OK ).

This tool can even help you automatically fix some errors by running fixjsstyle-strict fixme. js. (Note: not all errors can be fixed)
Closure Linter supports windows, Linux & Mac OS X. For more information, see here.
.

Article transferred from: http://www.jssay.com/blog/index.php/2010/09/03/javascript%E7%BC%96%E7%A8%8B%E8%A7%84%E8%8C%83/

Related Article

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.