function selectedSubreddit(state = 'reactjs', action) { switch (action.type) { case 'tr': return '突然' default: return state }}var a1 = { type: 'tr'}let selected = selectedSubreddit(,a1);console.log(selected);function selectedSubreddit(action,state = 'reactjs') { switch (action.type) { case 'tr': return '突然' default: return state }}var a1 = { type: 'tr'}let selected = selectedSubreddit(a1, );console.log(selected); // 突然
1 回答
ibeautiful
TA贡献1993条经验 获得超5个赞
问题中的示例,有默认值的参数state并不是尾参数,所以无法只省略这个参数,解决方法可以调用时显示输入undefined,即
let selected = selectedSubreddit(undefined, a1);
或者
function selectedSubreddit(action, state = 'reactjs') { }
,然后调用let selected = selectedSubreddit(a1, );
添加回答
举报
0/150
提交
取消