Please can someone explain to me what this line of code does:
var list = calls[ev] || (calls[ev] = {});
My best guess:
It\'s setting t
This code is equivalent to
var list;
if (calls[ev])
list = calls[ev];
else {
calls[ev] = {};
list = calls[ev];
}
Two features of the language are used:
a || b
. If a
is true
then b
is not evaluated). Thus, if you assign var v = a || b;
and a
evaluates to something that can be cast to true
, then b
is not evaluated.var a = b = c;
)The parentheses are necessary to avoid this interpretation:
var list = (calls[ev] || calls[ev]) = {};
(which is an error).