There was an error while loading. Please reload this page.
统一用 utf-8 使用linux换行符,如果用windows记事本打开代码变一陀说明成功了
长度不超过 80 个字符。如超过换行空双倍缩进(8个空格)
好
if (looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog || loooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 ) { }
缩进使用4个 空格。禁用 tab
if (foo) { }
坏
不允许一行判断,一律换行
if (foo) return;
if (foo) { return; }
##命名约定
单引号优先原则,只有需要多层嵌套和json字面量时才考虑用双引号
var foo = 'hello'; var letter = "I'm char1ee"; 或 var letter = 'I\'m char1ee'
var foo = "hello";
不要养成不写分号的坏习惯, 只在函数声明、if 判断 for while try等}后可以省略引号 好
var foo = 1; var bar = 2; function hello() { } if (condition) { }
逗号后空一格
var a, b, c; function (a, b, c) { }
var a,b,c; var a , b , c;
var x = y + z;
var x=y+z;
{ a: 'short', looooongname: 'long' }
{ a : 'short', looooongname: 'long' }
建议用自然人类的处理方法
{ a: 'a', b: 'b', c: 'c' }
不建议使用 npm 风格的逗号与换行,即
{ a: 'a' ,b: 'b' ,c: 'c' }
首先,变量在使用前必须声明。
对于单 var 模式和多 var 模式,不做强行约定,但同一个文件里,风格必须一致。
配合 .jshintrc 做机器校验