關於條件if/else語句,以下示例在功能上等效嗎?這些JS條件語句在功能上是否相同?
function isEntering() {
if (this.stage === 'entering') {
return true;
} else {
return false;
}
}
function isEntering() {
if (this.stage === 'entering') {
return true;
} return false;
}
function isEntering() {
if (this.stage === 'entering') {
return true;
}
}
isEntering = (this.stage === 'entering') ? true : false;
如果是這樣,我會使用最簡潔的選項。但只有四者在功能上等同。
'isEntering =(this.stage === '進入')' –
你省略'isEntering =()=> this.stage == ='進入';'。 – 2017-06-29 16:11:23
這個函數isEntering(){if(this.stage ==='entered'){ return true; } }'返回未定義的情況下,其他人將返回false,其他人相等 – baao