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/