1. 使用 /* … / 来进行多行注释,特别是方法,每一个参数的含义及默认值 ```javascript // bad // make() returns a new element // based on the passed in tag name // // @param {String} tag // @return {Element} element function make(tag) {

      // …

      return element; }

    // good /**

    • @description: 方法描述
    • @param {*} tag 参数描述 【默认值】
    • @return {} / function make(tag) {

      // …

      return element; } ```

    1. 使用 // 进行单行注释。 将单行注释放在需要注释的行的上方新行。 在注释之前放一个空行,除非它在块的第一行 ```javascript // bad const active = true; // is current tab

    // good // is current tab const active = true;

    // bad function getType() { console.log(‘fetching type…’); // set the default type to ‘no type’ const type = this.type || ‘no type’;

    return type; }

    // good function getType() { console.log(‘fetching type…’);

    // set the default type to ‘no type’ const type = this.type || ‘no type’;

    return type; }

    // also good function getType() { // set the default type to ‘no type’ const type = this.type || ‘no type’;

    return type; }

    1. 3. 用一个空格开始所有的注释,使它更容易阅读
    2. ```javascript
    3. // bad
    4. //is current tab
    5. const active = true;
    6. // good
    7. // is current tab
    8. const active = true;
    9. // bad
    10. /**
    11. *@description: 方法描述
    12. *@param {*} tag 参数描述 【默认值】
    13. *@return {*}
    14. */
    15. function make(tag) {
    16. // ...
    17. return element;
    18. }
    19. // good
    20. /**
    21. * @description: 方法描述
    22. * @param {*} tag 参数描述 【默认值】
    23. * @return {*}
    24. */
    25. function make(tag) {
    26. // ...
    27. return element;
    28. }
    1. 使用 FIXME 或者 TODO 开始你的注释可以帮助其他开发人员快速了解,如果你提出了一个需要重新审视的问题,或者你对需要实现的问题提出的解决方案。 这些不同于其他评论,因为他们是可操作的。 这些行为是 FIXME: — 需要解决这个问题 或者 TODO: — 需要被实现 ```javascript class Calculator extends Abacus { constructor() { super();

      // FIXME: 这里不应该使用全局变量 total = 0; } }

    class Calculator extends Abacus { constructor() { super();

    1. // TODO: total 应该由一个 param 的选项配置
    2. this.total = 0;

    } } ```