Internet Department-supplier Team JS specification

Source: Internet
Author: User

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

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.