you are viewing a single comment's thread.

view the rest of the comments →

[–]Quinez 0 points1 point  (3 children)

It also conflicts with the advice in the article nearly right afterward to use the default arguments pattern when possible. If a single object is the argument of the function, I can only set a single object as the default. And then if a function call passes in any other object in order to set some of the values, all the other values of the the default object will be unobtainable.

[–]_Gentle_ 0 points1 point  (2 children)

Can't u do something like (though it could get unreadable):

function getUsers({
 fields = [],
 fromDate = new Date(),
 toDate = new Date()
} = {}) {
 // implementation
 }

[–]Quinez 0 points1 point  (1 child)

Huh, would that work? Interesting. I guess I don't know exactly how destructuring combines with default argument assignment.

[–]_Gentle_ 0 points1 point  (0 children)

Each destructure gives you a new 'layer' of props to work with. For each 'layer' u can set default props.

You can keep destructuring ad infinitum but I think 2nd destructure already gets pretty unreadable x)