让我们把它放在一个对象中,为了便于阅读,我用括号括住了函数:
var myObj = {
_hasUI : true,
_markSelected : function(arg){some logic}
_refreshUI: function() {
this._hasUI &&
(
// Strat evaluation from the left to right
(g.empty(this.flowContainer),
(f.forEach(...) ),
(g.create(args) ),
(this._markSelected(arg) )
// End evaluation and return
// the result of this._markSelected(arg)
)
}
基本上,这意味着如果 this._hasUI 为真继续执行您找到的内容。在这种情况下,执行/评估第一个函数然后是第二个函数.. 直到最后一个函数,它将 仅返回最后一个函数的结果。
您可以找到其他东西,而不仅仅是一个函数,您可以在任何表达式中找到比较变量...
用整数查看相同的代码:
var secondExempleObj = {
_hasUI : true, // change it to false and see the difference
_refreshUI: function () {
return ( this._hasUI && (1,false,3,4) )
}
}
console.log('result : ' + secongExempleObj ._refreshUI());
// if _hasUI == true then the resutl will be 4
// if _hasUI == false you will get false
// _hasUI will work just like light switch if true -> continue to evaluate the rest of expressions else get out of there so we can replace it like so
var thirdObj = {
numbers : [1,87,30],
sumFunction : function(n1,n2,n3){ console.log(n1+n2+n3) },
_hasUI : true,
_refreshUI: function () {
if(this._hasUI == true){
return (1,false,this.sumFunction(...this.numbers),4)
}else{
return false;
}
}
}
console.log('result : ' + thirdObj._refreshUI());
// it will console log 118 then 4
// if you switch _hasUI to false it will logout false
希望对你有意义