el && fn.call(el, e, el) I feel a little confused when this code is written like this.
If you want to call fn, why not write fn.call(el, e, el) directly. However, there is an & sign in front of
. He wants to find a Boolean value without returning. What's the point of finding true or false
in this way?
Uses the short circuit property of
&&
.in
A && B
means that if
A
is false, then the entire expression is false and there is no need to evaluateB
.If
A
is true, then evaluateB
to judgeSo the above code means
If
el
is true, then executefn.call(el, e, el);
||
also has similar properties:If the lvalue is true, the following does not need to be evaluated.
For example, used to specify the default value
If el exists, the following function will be called, otherwise it will not be called
a && b is equivalent to
if (a){
}