The usage in question is specific to redux.js
. The default value for the first parameter is generally useless in function calls because of the second parameter without default.
However, as said earlier in the same tutorial about Reducers:
Redux will call our reducer with an undefined state for the first
time. This is our chance to return the initial state of our app:
function todoApp(state, action) {
if (typeof state === 'undefined') {
return initialState
}
//...
return state
}
So the 1st parameter isn't really omitted here. Redux is supplying undefined
as its value on initialization. It is only in this case, the tutorial used default arguments syntax as a shortcut:
function todoApp(state = initialState, action) {
//...
return state
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…