Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

javascript - Expected an assignment or function call and instead saw an expression

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);

as opposed to:

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;
};

into the minifier it minifies down to this anyway:

window.test=function(a){var b=[];a&&b.push(a);return b};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...