开发者

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

开发者 https://www.devze.com 2023-03-14 01:30 出处:网络
This question already has answers here: Closed 开发者_Go百科11 years ago. Possible Duplicate: Javascript : assign variable in if condition statement, good practice or not?
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

精彩评论

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