codecamp

杂项

不要混用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) {


}
jshint
sublime3插件
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

编辑器配置和构建检查

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }