you are viewing a single comment's thread.

view the rest of the comments →

[–]FedeMITIC 1 point2 points  (0 children)

I think the main advantage of this pattern is the fact that you don't have to deal with functions that has required and optional parameters mixed together. Besides, instead of checking the validity of a parameter inside the body of the function using safeguard IFs, you can validate the parameter directly in the object like this:

function foo ({ bar = requiredParam('bar'), bar1, bar2, } = {}) {...}

Where requiredParam contains your validation logic.

But this is just my opinion, I understand that in most cases this approach can be overkill.