JSLint不期待我的倾斜 [英] JSLint doesn’t expect my tildes

查看:70
本文介绍了JSLint不期待我的倾斜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSLint坚持认为我使用了某些异国情调的代字号运营商在下面的示例中是意外的。我想知道这是否是JSLint的限制?还是严格模式?或者我还缺少什么?

JSLint insists that my use of the somewhat exotic tilde operator in the below example is unexpected. What I’m wondering is whether this is a limitation of JSLint? or strict mode? or what else am I missing?

(function () {
    'use strict';
    if (~'foo'.indexOf('bar')) {
        return 'wild accusations';
    }
}());

另外,为什么我不应该使用简单的代字号运算符而不是下面更复杂的示例?当然必须有充分的理由不这样做?

Also, why shouldn’t I use the simple-looking tilde operator instead of the more complex example below? Surely there must be a good reason not to?

if ('foo'.indexOf('bar') >= 0) { … }


推荐答案

来自JSLint文档


按位运算符

Bitwise Operators

JavaScript没有整数类型,但它确实有按位运算符。按位运算符将其操作数从浮点转换为整数和返回,因此它们不如C或其他语言有效。它们在浏览器应用程序中很少有用。与逻辑运算符的相似性可以掩盖一些编程错误。按位选项允许使用这些运算符:<< >> >>>〜& |。

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: << >> >>> ~ & |.

您可以在选项

干杯

这篇关于JSLint不期待我的倾斜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆