我输入cross-browser split进入我的代码并通过 jsHint 运行它并在行中得到 Unexpected use of '>>>'
:
limit = limit === undef ?
-1 >>> 0 : // Math.pow(2, 32) - 1
limit >>> 0; // ToUint32(limit)
当我把它放在一行中并将表达式放入括号时也是如此
这是错误吗?我该如何修复它?
最佳答案
您可以通过关闭“当使用按位运算符时”选项(列出的顶部选项 here 来禁用该错误(好吧,他们确实应该将其称为警告) - 奇怪的是,文档没有提及所有与其相关的按位运算符);如果这样做,上面的代码不会产生错误。
Here's the rationale有关使用原始 JSLint 工具中的按位运算符的警告(JSHint 是 JSLint 的更友好版本,具有更多选项来关闭纯样式的“错误”):
Bitwise Operators
JavaScript does not have an integer type, but it does have bitwise operators. The bitwise operators convert their operands from floating point to integers and back, so they are not as efficient as in C or other languages. They are rarely useful in browser applications. The similarity to the logical operators can mask some programming errors. The
bitwise
option allows the use of these operators:<<
>>
>>>
~
&
|
.
关于javascript - 跨浏览器拆分中意外使用 '>>>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11176878/