杂项

2025-08-06 18:23 更新

不要混用tabspace
不要在一处使用多个tabspace
换行符统一用LF
对上下文this的引用只能使用_this, that, self其中一个来命名;
行尾不要有空白字符;
switch 的 falling through 和 no default 的情况一定要有注释特别说明;
不允许有空的代码块。

示例代码

// not good
var a   = 1;


function Person() {
    // not good
    var me = this;


    // good
    var _this = this;


    // good
    var that = this;


    // good
    var self = this;
}


// good
switch (condition) {
    case 1:
    case 2:
        ...
        break;
    case 3:
        ...
    // why fall through
    case 4
        ...
        break;
    // why no default
}


// not good with empty block
if (condition) {


}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号