Javascript Variable Declaration With ||
I'm investigating Three.js at the moment and have come across this variable declaration at the top of the main source file: var THREE = THREE || { REVISION: '52' }; I'm just wonde
Solution 1:
The above means:
If the value of THREE
evaluates to true
, assign the value of THREE
to the THREE
variable, otherwise initialize it to the object { REVISION: '52' }
.
Solution 2:
In code, it's like saying:
var THREE;
if (THREE) {
THREE = { REVISION: '52' };
}
else {
THREE = THREE;
}
Or:
var THREE = (THREE) ? { REVISION: '52' } : THREE;
Solution 3:
lazy instantiation. If the variable is declared already, then assign a value to it.
Post a Comment for "Javascript Variable Declaration With ||"