gpt4 book ai didi

javascript - 如何将两个 JavaScript 语句合并为一个

转载 作者:搜寻专家 更新时间:2023-11-01 04:58:01 25 4
gpt4 key购买 nike

有时我想将两个语句合二为一以省略条件语句中的大括号。例如,在 PHP 中,而不是写

if ($direction == 'south-east') {
$x++;
$y++;
}

我会写

if ($direction == 'south-east') $x++ and $y++;

但是有没有办法在 JavaScript 中做到这一点?编写 x++ && y++ 似乎不起作用。

最佳答案

花括号并没有那么糟糕,但是 - 在非常特殊的情况下 - 你可以 enhance your code by using commas :

if (direction == 'south-east') x++, y++;

这是 fiddle :http://jsfiddle.net/FY4Ld/

关于javascript - 如何将两个 JavaScript 语句合并为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12060505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com