期望一个赋值或函数调用,而是看到一个表达式 [英] Expected an assignment or function call and instead saw an expression

查看:276
本文介绍了期望一个赋值或函数调用,而是看到一个表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此 JSLint 错误感到非常满意。我怎么能忍受呢?它有一个标志或复选框吗?

I'm totally cool with this JSLint error. How can I tolerate it? Is there a flag or checkbox for it?

当你做类似的事情时,你会得到它:

You get it when you do stuff like:

v && arr.push(v);

而不是:

if (v) {
    arr.push(v);
}

两者都做同样的事情。如果你把:

Both do the same exact thing. If you put:

window.test = function(v) {
    'use strict';
    var arr = [];
    if (v) {
        arr.push(v);
    }
    return arr;
};

进入 minifier 它最终减少到这个:

into the minifier it minifies down to this anyway:

window.test=function(a){var b=[];a&&b.push(a);return b};


推荐答案

我不认为JSLint可以选择转向关闭。

I don't think JSLint has an option to turn that off.

JSHint (包含更多选项的分叉)有一个选项但是,对于它: expr 选项,记录为如果允许ExpressionStatement作为程序。

JSHint (a fork with more options) has an option for it, though: The expr option, documented as "if ExpressionStatement should be allowed as Programs".

这篇关于期望一个赋值或函数调用,而是看到一个表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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