【发布时间】:2014-12-15 15:07:38
【问题描述】:
假设我想将一堆变量设置为 null(并且不想使用数组/循环结构),或者我只想跨多行编写一个大型布尔表达式。在这种情况下,未闭合的括号会阻止分号插入吗?例如
some_variable = another_variable = yet_another_variable = (
oh_look_a_parenthesis_above_me = hey_heres_another_variable) = (
and_for_some_reason_another = last_one) = null;
或者
if(test_for_some_complex_expr && another_test || (
but_maybe_this_one && or_this_one)) {
// ...
}
这与使用 && 或 || 或 = 在换行符上对表达式进行分组相比如何?即,这也总是有效吗?
some_variable = another_variable =
a_variable_after_a_line_break = and_one_more;
while(test_for_an_expr && another_test ||
(an_expr_here && and_an_expr_here)) {
// ...
}
我正在寻找在所有浏览器(包括 IE6+)中最标准的方式。
【问题讨论】:
-
AFAIK,JavaScript 不关心空格(让您的担忧变得毫无意义)。
-
@Brad:在某些情况下,JavaScript 实际上确实关心换行符。
-
@JacquesB:只有引用的字符串和一些逻辑情况,但我更多地指的是延长条件表达式。
标签: javascript line-breaks automatic-semicolon-insertion