How to destructure option argument with all default values in ES6?

前端 未结 1 1723
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 12:32

I use ES6 features with babel compiler. I have a function which takes option object as an argument:

function myFunction({ option1 = true, option2 = \'whateve         


        
相关标签:
1条回答
  • 2020-11-30 13:14

    Yes, you just have to provide a default value for the complete argument:

    function myFunction({option1 = true, option2 = 'whatever'} = {}) {
    //                                                         ^^^^
        console.log(option1, option2);
        // do something...
    }
    
    0 讨论(0)
提交回复
热议问题