據我所知,我有兩個功能完全相同。唯一的區別是一個是簡潔的主體,另一個是 ES6 之前的長版本。簡潔的版本有效,而另一個則無效。更長的版本有什么問題?
//this version of the getActualSleepHours function works
const getActualSleepHours = () =>
getSleepHours('monday')
getSleepHours('tuesday')
getSleepHours('wednesday')
getSleepHours('thursday')
getSleepHours('friday')
getSleepHours('saturday')
getSleepHours('sunday');
//this version of the getActualSleepHours function doesn't work
const getActualSleepHours = function() {
getSleepHours('monday')
getSleepHours('tuesday')
getSleepHours('wednesday')
getSleepHours('thursday')
getSleepHours('friday')
getSleepHours('saturday')
getSleepHours('sunday');
}
uj5u.com熱心網友回復:
該() => something()語法在 之前插入一個隱式回傳something()。要使這些函式等效return,請在函式中添加 a:
function() {
return getSleepHours('monday')
getSleepHours('tuesday')
getSleepHours('wednesday')
getSleepHours('thursday')
getSleepHours('friday')
getSleepHours('saturday')
getSleepHours('sunday');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/474887.html
標籤:javascript 功能 语法错误
上一篇:我們可以在C中使用雙函式指標嗎?
