Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

js中if语句判断条件用逗号隔开是什么意思

代码中有以下语句:

if ($(".goProdList").click(function () { window.location.href = "./prodList.html"}), $(".navbar ul li.nav-main").addClass("active"), username) {
    ...此处省略一系列逻辑代码
}

不理解 if 的判断条件用逗号隔开是什么意思,如果写成普通的格式,是下面这种吗:

$(".goProdList").click(function () { window.location.href = "./prodList.html"});
$(".navbar ul li.nav-main").addClass("active");
if(username) {
    ...此处省略一系列逻辑代码
}

求解答~~


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

1 Answer

0 votes
by (71.8m points)

逗号操作符 ?对它的每个操作数求值(从左到右),并返回最后一个操作数的值。

let x = 1;

x = (x++, x);

console.log(x);
// expected output: 2

x = (2, 3);

console.log(x);
// expected output: 3

你的展开没问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...