[英]JSLint warns about ternary operator
I have the following code in JavaScript: 我在JavaScript中有以下代码:
var a = num ? 5 : "five";
Code seems to be workable. 代码似乎可行。 But JSLint warns like this:
但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
So what the problem is? 那么问题是什么? How to disable such warnings?
如何禁用此类警告?
Its opinion is that: 它的意见是:
The ternary operator can be visually confusing, so
?
三元运算符可能在视觉上混乱,所以
?
question mark and:
colon always begin a line and increase the indentation by 4 spaces.问号和
:
冒号总是开始一行,并将缩进增加4个空格。\nvar a = hvar a = h\n ?
? 5
五\n : "qwerty";
:“qwerty”;\n
To fix either comply with the rule or tick messy whitespace . 要修复遵守规则或勾选凌乱的空白 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.