Quantcast
Viewing all articles
Browse latest Browse all 12

Partial default arguments

getify wrote:

IIUC, to apply default values per property in the params list, you need to destructure the object passed in (which btw you called info in one place and options in the other). But you can't destructure in the params list AND then recombine into a single param name like info. That second step needs to be separate in the body of the function. Try this:

var userInfo = (
    {name = 'Mr.Coder', codes = ['js','python','ruby','perl']}
) => { let info = {name,codes}; console.log(info); }

userInfo({
  name: 'ljharb'
});

I think that produces what you want. Image may be NSFW.
Clik here to view.
smile

Read full topic


Viewing all articles
Browse latest Browse all 12

Trending Articles