JSLint报告意外使用'&'和'|' - 我想清理一下 [英] JSLint reports unexpected use of '&' and '|' -- I'd like to clean this
问题描述
我正在尝试将我的Javascript代码100%JSLint清理干净。
I'm trying to get my Javascript code 100% JSLint clean.
我已经从其他地方获取了一些JS代码来创建UUID 。该代码包含以下行:
I've got some JS code that I've lifted from elsewhere to create a UUID. That code has the following line:
s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1);
此行煽动JSLint生成两条错误消息:
This line incites JSLint to generate two error messages:
1) Unexpected use of '&'
2) Unexpected use of '|'
我不明白为什么 - 我很欣赏有关如何重新编码消除错误信息的建议。
I don't understand why -- I'd appreciate counsel regarding how to recode to eliminate the error message.
推荐答案
为什么的原因是JS中的实际按位操作非常罕见,并且出现在JS代码中的那些运算符几乎总是布尔版本的错误( &&&
, ||
)。这就是JSLint关心的原因。这是对按位操作的合法使用。我相信您可以使用按位
标记来消除警告:
The reason "why" is that actual bitwise operations are exceedingly rare in JS, and those operators appearing in JS code almost always are a typo for the boolean versions (&&
, ||
). That's why JSLint cares. This is a legit use of bitwise ops though. I believe you can silence the warning with the bitwise
flag:
/*jslint bitwise: true */
这篇关于JSLint报告意外使用'&'和'|' - 我想清理一下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!