DEV Community

Discussion on: Extract Functions Arguments using Destructure in JavaScript

Collapse
 
nombrekeff profile image
Keff

Nice read!
Really well explained, I tend to use objects for this purpose, so the user sees the parameter names on the function call, but this is a great approach as well, even better if using arguments.

Collapse
 
samanthaming profile image
Samantha Ming

Thanks Manolo! And glad you found it helpful!

Totally, passing object is super cool! which kinda acts like named parameters where you don't have to worry about the order. I believe this is what you're referring to:

// Boo, arguments must be in specific order
function meal(protein, carb, veggie){
}
meal('πŸ₯©', '🍚', 'πŸ₯¦')


// Yay, arguments can be in any order
function meal2({protein, carb, veggie}){
}
meal2({carb: '🍚', veggie: 'πŸ₯¦', protein: 'πŸ₯©'})

I have a tidbit on it as well > samanthaming.com/tidbits/18-named-... 😊

Collapse
 
nombrekeff profile image
Keff

Yup that was exactly it :) I'll check it out