3 回答
TA贡献1836条经验 获得超13个赞
var _ = ((obj.fn && obj.fn() ) || obj._ || ( obj._ == {/* something */}))? true: false
更新
true
false
var a = 1 || 2;// a = 1// it's because a will take the value (which is not null) from leftvar a = 0 || 2;// so for this a=2; //its because the closest is 2 (which is not null)var a = 0 || 2 || 1; //here also a = 2;
var _ = (obj.fn && obj.fn() ) || obj._ || ( obj._ = {} );// _ = closest of the expression which is not null // in your case it must be (obj.fn && obj.fn())// so you are gettig this
var a = 1 && 2;// a = 2var a = 1 && 2 && 3;// a = 3 //for && operator it will take the fartest value // as long as every expression is truevar a = 0 && 2 && 3;// a = 0
var _ = obj && obj._;// _ = obj._
TA贡献1873条经验 获得超9个赞
||
&&
X || Y
, X
Y
Y
Y
X || Y
X || Y
Y
Y
&&
false
, 0
, -0
, ""
, null
, undefined
, NaN
document.all
"false"
false
TA贡献1871条经验 获得超13个赞
||
&&
"" && "Dog" // ""
"Cat" && "Dog" // "Dog"
"" || "Dog" // "Dog"
"Cat" || "Dog" // "Cat"
添加回答
举报