问题
Possible Duplicate:
What does this construct mean?
I'm encountering this syntax for the first time and am not sure what it's doing:
self.name = _searchString(settings.dataBrowser) || "An unknown browser";
What does the or (double pipes) condition do? When would self.name be set to the second value?
回答1:
This is the logical or operator.
It evaluates to its first "truthy" operand.
In particular, it will evaluate to the second operand if the first operand is "falsy" — null, false, undefined, 0, "", or NaN.
回答2:
Crockford calls / called it a default operator
回答3:
this is directly related to a question i have asked, you can read about it here Short-circuit evaluation via the AND operator in PHP
so basically, it sets self.name to the value returned from the function, but if the function returns false, it sets itself to "An unknown browser";
来源:https://stackoverflow.com/questions/7718259/what-does-mean