javascript - 跨浏览器拆分中意外使用 '>>>'

标签 javascript split jshint

我输入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/

相关文章:

sql - 比较来自两个不同表的两列的逗号分隔值

javascript - 根据 jshint 的错误检测而无需进一步检查,将 == 更改为 === 是否安全

javascript - 在全局范围内预定义变量有什么优点?

javascript - JS : Why isn't this variable available to the other functions?

javascript - 具有特定宽度的水平向导导航

javascript - 基于多个 CSS 类和来自多个复选框的输入显示/隐藏 tr 元素

java - 使用正则表达式拆分 JSON 有效负载以获取值

python - 嵌套 NumPy 数组并使用拆分等方法

gulp - 如何让 gulp-jshint 忽略文件夹

javascript - 使用 Metrics Graphics.js 时出现 TypeError