" in a var statement mean?
Possible Duplicate:
null coalescing operator for javascript?
What does “options = options || {}” mean in Javascript?
Can someone explain me this expression? I stumbled accros the javascript line of code and I wondered what it means.
var node = element.node || element[element.length - 1].node;
node get's used like this below:
if (node.nextSibling) {
node.parentNode.insertBefore(this.node, node.nextSibling);
} else {
node.parentNode[appendChild](this.node);
}
At first i though node should be a boolean or something but it's not. Am I correct if i think that the meaning is: node is element.node but if the node attribute is undefined node is the last element in the array of element?
Your understanding is along the right lines; be aware that even if element.node
is defined, but is a falsey value ( 0
, false
etc.) that element[element.length - 1].node
will be assigned to node
instead.
Simple answer: it means OR
:)
Reference: http://www.w3schools.com/js/js_operators.asp
这意味着,如果element.node
的值在布尔表达式中表示为True,那么node
将是element.node
,否则它将是element[element.length - 1].node
下一篇: “在var语句中是什么意思?