The specification distal WEB javascript

JavaScript is a weakly typed language, and as such lead to the wording varied, here compiled some issues when writing code to note

General specification

file encoding

To avoid garbled contents, use unified UTF-8coding saved.

At the end of the file, leave a blank line.

Code detection

Open eslintcode specifications and error checking.

In strict mode coding mode

'use strict';

Type specification

  • js data types string, number, boolean, null, undefined, array, function, and these types of object, different types have different data storage, but also has not a corresponding use of the data assigned to note the following

    • The initial value of the type you want to clear
    • Do not free to change the type of
  • Type detection 优先使用 typeof. Object type detection used instanceof. detection of null or undefined use == null.

  • At the beginning and end of the string using single quotes '...string...'

Naming conventions

  • A small hump variable naming names, such as: addUser password studentID

  • Named constant use of the word in all capital letters, separated by an underscore, such as: FORM_NAME

  • For objects, functions, and examples of a small hump (camelCase) nomenclature

    // 对象
    let isObject = {};
    // 函数
    function isFun(){
     ...
    };
    // 实例
    let myBbj = new Object();
    web前端开发资源Q-q-u-n: 767273102 ,内有免费开发工具,零基础,进阶视频教程,希望新手少走弯路 
    

*   对于类命名或者构造函数,采用大驼峰命名 User() DateBase()

    ```
    // 类
    class Point {
      ...
    };

    // 构造函数
    function User(options) {
      this.name = options.name;
    }

    let myBbj = new User({
      name: 'yup'
    });
   
    ```

## 代码规范

### 缩进

统一使用`两个空格缩进`,不推荐使用 tap 缩进。

### 引号

统一使用`单引号`。

### 换行

每个独立语句结束后必须换行。

### 分号

不得省略语句结束的分号

### 代码块

使用花括号包裹所有的多行代码块。

*单行 if 语句也必须使用花括号括住*

// recommended
IF (to true) {
// TODO ...
}


// not recommended
if (true) // TODO ...


### 使用全等符号

在等号表达式中使用类型严格的 `===`和`!==`。使用 === 可以避免等于判断中隐式的类型转换。

Recommended @
IF (Age 30 ===) {
// ...
}


// Not recommended
IF (== Age 30) {
// ...
}


## 注释规范

### 单行注释

使用 `//`  作为单行注释。在评论对象上面另起一行使用单行注释。在注释内容前插入一个空格。

// a single line comment


### 多行注释

以`/*`开头,`*/`结尾,注释内容前后加一个空格

/*

  • The first line comments
  • The second line comment
    * /

/ * Another written * /


### 方法注释

函数(方法)注释也是多行注释的一种,但是包含了特殊的注释要求,关键方法必须加注释。

/**

  • Methods Functional Description
  • @param {*} parameter
  • @param {*} parameter
  • @param {*} parameter
  • @param {*} parameter
  • @return return value
    * /
    Web front-end development resources Qqun: 767273102, there are free development tools, zero-based, advanced video tutorials, I hope the novice detours

### TODO 注释

使用  // TODO:  标注问题的解决方式。

function Calculator() {
// TODO: total should be configurable by an options param
}






Guess you like

Origin blog.csdn.net/nnnn1235657/article/details/94763899