File naming
Page, JS file naming: The use of an underlined connection, for example, said: error-report.html
JS folder naming: Scripts
Public JS naming: Common.js
File Structure Organization
Each page in the unique JS file,/scripts folder JS file structure should be consistent with the page structure
Grammar
| Variable declaration |
functionDosomethingwithitems(Items){VarValue=10,Comment Ah, comment ah, proResult=Value+10//comment Ah, comment i //comments Ah, comments ah, pro len//comment Ah, note ah, pro for (i= 0len=items . lengthi < leni++) {dosomething (items[i}} /span>
all in-function variable declarations are placed inside the function head, using only one VAR and must also use Var
|
| Standard variable with hump marking |
var thisismyname; |
| function declaration |
var doSomething = function (item) { // 内容};
|
| Align brackets |
if (condition) { doSomething() } 花括号必须要,即使内容只有一行
|
| Add a blank line between a method, a single-line or multiline comment, and a logical block to increase readability |
|
| Leave a space after the comma and semicolon |
var values = [1, 2, 3, 4, 5, 6, 7], I, Len; For (i=0, len=values.length; i<len; i++) { Process (Values[i]); } |
| Single quote ' with character constants uniform |
var str = ' 123 '; |
| For-in |
VarProp;For(PropInchobject {//note there must be a hasownproperty judgment, otherwise jslint Or Jshint will have a warn! if (object. Hasownproperty (prop{ Console. Log ( "property name is" + prop); console. Log ( "property value is" + object [prop}} /span>
|
| switch |
switch ( Condition) {case "first" : //code breakcase "third" : //code breakdefault: //code} switch and parentheses have spaces between them Leave a blank line in the middle of the next case after break |
| constructor, uppercase first letter |
function Person(name) { this.name = name; }
|
| Use the ID of the place must be all uppercase |
var Goodid; |
| Use a URL where it must all be capitalized |
var Reporturl; |
| Constants in uppercase letters, underlined by the way the connection |
var max_count = 10; |
Internet Department-supplier Team JS specification