Recently also have no mind to write articles, feel always have busy things, ah. But these days began to study titanium, found that its official production of the MVC Framework (Alloy) is quite good, just started to suffer from the lack of good code to learn, documents and less, so has not been to study in detail, and then found the original official Codestrong is a set of very good learning code, as long as the whole code to see through it, I believe that the use of alloy will be the basic ~
While looking at its source code, it is found that many places use the following usage:
$.clouds && ($.index.add ($.clouds));
The beginning is not very understanding, after all, the usual use of less, on the next Google to know that the original writing is very convenient and easy to use (in fact, the source of jquery is also a large number of uses this method). The following quotes a section of the Internet to find explanations && and | | Alternative usage in javascript:
A () && B (): If True after a () is executed, B () is executed and the value of B is returned, and if A () is returned false, the entire expression returns the value of a (), and B () is not executed;
A () | | B (): If True after a () is executed, the entire expression returns the value of a (), B () is not performed, and if A () is returned false, B () is executed and the value of B () is returned;
&& priority is higher than | |
After reading is quite clear, and then look at the specific code:
Alert ((1 && 3 | | 0) && 4); Results 4①
alert (1 && 3 | | 0 && 4);//Results 3 ②
alert (0 && 3 | | 1 && 4);//Results 4③
Analysis:
Statement ①:1&&3 return 3 => 3 | | 0 Return 3 => 3&&4 return 4
Statement ②: First executes 1&&3 return 3, returns 0 in execution 0&&4, finally executes the result comparison 3| | 0 Return 3
Statement ③: First executes 0&&3 return 0, returns 4 in execution 1&&4, finally executes the result comparison 0| | 4 return 4
Note: Integers other than 0 are true,undefined, NULL, and null string "" to false.
I feel that JavaScript is really very strong and flexible Oh, hehe ~ ~