I am running Node v6.6.0, which has support for destructuring function arguments:
function foo ({ a: { b }}) {
// stuff
}
Suppose I want to destructure and access both a and b. Sadly the following doesn't seem to work:
function foo ({ a: { b }}) {
return [a, b]
}
foo({ a: { b: 123 }})
// ReferenceError: a is not defined!
Is this bug in Node or is this the expected behavior for ES6? Shouldn't both a and b be defined in the function? If not, why does destructuring have the effect of un-defining a base property name (a)?
Is there a way I can use parameter destructuring to get both a and b defined in the function? I'm explicitly trying to avoid manually destructuring them.
amerely designates what property of the parameterbis to be taken from. It is not defined or accessible as a parameter. If you want to accessa, you will have to extractbyourself within the function.