ecmascript 6 - Use JavaScript object destructuring for default values and rebuild -


it's won't positive answer question, i'll ask anyway.

i have function taking object parameter.

function myfunc(options) {} 

this object contains properties i'd assign default values to. using destructuring, can this:

function myfunc({   mandatory_field, // without default value   = 1,   j = 2,   k = 3,   obj: {     prop1 = 'val',     prop2 = 2   } = {},   str: 'other val' } = {}) {} 

now, inside function, have these variables either default value or ones passed, great.
howevever, need pass options object other functions, in end, i'll need rebuild way:

function myfunc({   mandatory_field, // without default value   = 1,   j = 2,   k = 3,   obj: {     prop1 = 'val',     prop2 = 2   } = {},   str: 'other val' } = {}) {   let options = {     mandatory_field,     i,     j,     k,     obj: {       prop1,       prop2     },     str   };   otherfunc1(options);   otherfunc2(options); } 

but feels redundant.

i thought aliasing destructured object work, it doesn't.
there cleaner way think of this?


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -