It means the title
argument is optional.(这意味着title
参数是可选的。)
So if you call the method with no arguments it will use a default value of "Error"
.(因此,如果不带任何参数调用该方法,它将使用默认值"Error"
。)
It's shorthand for writing:(它是写作的简写:)
if (!title) {
title = "Error";
}
This kind of shorthand trick with boolean expressions is common in Perl too.(这种带有布尔表达式的速记技巧在Perl中也很常见。)
With the expression:(带有表达式:)
a OR b
it evaluates to true
if either a
or b
is true
.(它的计算结果为true
如果任a
或b
为true
。)
So if a
is true you don't need to check b
at all.(因此,如果a
为true,则根本不需要检查b
。) This is called short-circuit boolean evaluation so:(这称为短路布尔评估,因此:)
var title = title || "Error";
basically checks if title
evaluates to false
.(基本上检查title
评估结果是否为false
。)
If it does, it "returns" "Error"
, otherwise it returns title
.(如果是这样,它将“返回” "Error"
,否则返回title
。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…