I started to study Titanium again and found that its official MVC framework (Alloy) was quite good. At first, I was struggling to learn without good code and there was little documentation, so I didn't study it in detail. Later I found that the official CodeStrong is a very good set of learning codes. As long as I read the entire set of codes, I believe I can basically know how to use Alloy~
While looking at its source code, I found that many places use usage such as the following:
$.clouds && ($.index.add($.clouds));
I didn't understand it very much at first, after all, I usually use it in this way. After going to Google, I realized that this way is very convenient and easy to use (in fact, this method is also used a lot in the source code of jquery). The following quotes an explanation found online && and || alternative usage in javascript:
a() && b() : If true is returned after executing a(), then b() is executed and the value of b is returned; if false is returned after executing a(), the entire expression returns the value of a(), and b() does not execute;
a() || b() : If true is returned after executing a(), the entire expression returns the value of a(), and b() does not execute; if false is returned after executing a(), b() is executed and the value of b() is returned;
&& Priority is higher than ||
After reading it, it's quite clear, let's take a look at the specific code:
alert((1 && 3 || 0) && 4); //Result 4 ①
alert(1 && 3 || 0 && 4); //Result 3 ②
alert(0 && 3 || 1 && 4); //Result 4 ③
analyze:
Statement ①: 1&&3 Return 3 => 3 || 0 Return 3 => 3&&4 Return 4
Statement ②: First execute 1&&3 and return 3, then execute 0&&4 and return 0, and finally execute results comparison 3||0 and return 3
Statement ③: First execute 0&&3 and return 0, then execute 1&&4 and return 4, and finally execute results comparison 0||4 and return 4
Note: Integers that are not zero are true, undefined, null and empty strings are false.
I feel that JavaScript is really strong and flexible!!