samanime - 9 months ago 45
Javascript Question

# Get object that was destructured in parameter

Suppose I have a function that takes a destructured object as a parameter in an arrow function:

const myFunc = ({a, b, c}) => {
};


Is there anyway or syntax that would allow me to get that whole object as a single value as well? Since the arrow function doesn't bind
arguments
, I can't use that.

Is it possible to name it, something along the lines of:

const myFunc = (allArgs: {a, b, c}) => {
console.log(allArgs);
};
myFunc({a:1, b:2, c:3}); // Output: {a:0, b:1, c: 2}


Obviously, this isn't a deal breaker and there are plenty of workarounds (either don't use an arrow function, don't destructure, or recreate the object when I need it), but I'd like to know for convenience sake.

const myFunc = (allArgs = {a, b, c}) => {
myFunc({a:1, b:2, c:3}); // Output: {"a":1, "b":2, "c": 3}