JSLint 对三元运算符发出警告
JSLint warns about ternary operator
我在JavaScript中有以下代码:
var a = num ? 5 : "five";
代码似乎可行。但是 JSLint 会这样警告:
#2 Expected '?' at column 9, not column 15.
var a = h ? 5 : "qwerty"; // Line 10, Pos 15
#3 Expected ':' at column 9, not column 19.
var a = h ? 5 : "qwerty"; // Line 10, Pos 19
那么问题是什么?如何禁用此类警告?
其观点是:
The ternary operator can be visually confusing, so ?
question mark and
:
colon always begin a line and increase the indentation by 4 spaces.
var a = h
? 5
: "qwerty";
要修复要么遵守规则要么勾选乱码。
我在JavaScript中有以下代码:
var a = num ? 5 : "five";
代码似乎可行。但是 JSLint 会这样警告:
#2 Expected '?' at column 9, not column 15. var a = h ? 5 : "qwerty"; // Line 10, Pos 15 #3 Expected ':' at column 9, not column 19. var a = h ? 5 : "qwerty"; // Line 10, Pos 19
那么问题是什么?如何禁用此类警告?
其观点是:
The ternary operator can be visually confusing, so
?
question mark and:
colon always begin a line and increase the indentation by 4 spaces.var a = h ? 5 : "qwerty";
要修复要么遵守规则要么勾选乱码。