开发者

Bad practice to put = inside javascript if statement? [duplicate]

This question already has answers here: Closed 开发者_Go百科11 years ago.

Possible Duplicate:

Javascript : assign variable in if condition statement, good practice or not?

Is it bad practice to assign/evaluate things inside an if statement?

eg.

var foo;
var bar = function() { .. }

if(foo = bar()) {
    ..
}


Functionality-wise there's absolutely nothing wrong with that. But if you're going for readability, keep in mind that more junior members of your team (if any) may have a tougher time with less straight forward syntax as this.


This will work fine and is not bad practice in Javascript.

JSLint might not agree with me though ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜