es6中selectedSubreddit(,a1)怎么传递参数为什么错误?

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); // 突然


千万里不及你
浏览 472回答 1
1回答

ibeautiful

问题中的示例,有默认值的参数state并不是尾参数,所以无法只省略这个参数,解决方法可以调用时显示输入undefined,即let selected = selectedSubreddit(undefined, a1);或者function selectedSubreddit(action, state = 'reactjs') { },然后调用let selected = selectedSubreddit(a1, );
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript