Not used to see many arrow function (without being small ones, in array.map for example) so i got a bit confused with the parameter line :
{ searchKeys = typeof searchValue === "string", maxDepth = 20 } = {}
Would you mind to explain in a few words why it is there? :)
But that's just more verbose. Destructuring an empty object (if undefined is provided) is perfectly adequate, and gives defaults for all keys.
functionfn(searchValue,// this is the v below that we are depending on, it has to come first.{searchKeys=typeofsearchValue==="string",maxDepth=20}={}){/* ... */}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Not used to see many arrow function (without being small ones, in array.map for example) so i got a bit confused with the parameter line :
{ searchKeys = typeof searchValue === "string", maxDepth = 20 } = {}
Would you mind to explain in a few words why it is there? :)
Thank you in advance.
Sure, this doesn't depend on it being an arrow function, can be in a
function
just as well.This is the equivalent function:
First, we replace the point access with destructuring:
Next, we replace the conditional expressions for defaults with defaults in destructuring AND default in parameter:
Finally, to avoid having to think of a name for the short-lived
arg
binding, we can just YEET it right into the parameter list:We could write it like this:
But that's just more verbose. Destructuring an empty object (if
undefined
is provided) is perfectly adequate, and gives defaults for all keys.