javascript - Get object that was destructured in parameter -


this question has answer here:

suppose have function takes destructured object parameter in arrow function:

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

is there anyway or syntax allow me whole object single value well? since arrow function doesn't bind arguments, can't use that.

is possible name it, along 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, isn't deal breaker , there plenty of workarounds (either don't use arrow function, don't destructure, or recreate object when need it), i'd know convenience sake.

you destructure single param quite easily. lose advantage of terse destructuring syntax in arguments, it's easy , still clear:

const myfunc = (allargs) => {     const {a, b, c} = allargs;     console.log(allargs); }; 

alternatively, consider whether need arrow function. if don't need access lexical this perhaps old-fashioned function() {} trick , give access arguments.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -