How can I implement ES6 with Destructuring to give users options? I'm having trouble dealing with nested objects and preventing the defaults from being overwritten by partial objects.
Check out this simple example on MDN:
function drawES6Chart({size = 'big', cords = { x: 0, y: 0 }, radius = 25} = {})
{
console.log(size, cords, radius);
// perform some chart drawing
}
drawES6Chart({
cords: { x: 18},
radius: 30
});
The result displayed is
big {"x":18} 30
but what I actually want to see is
big {"x":18,"y": 0} 30
The provided cords object is incomplete and removes the default y value. My goal is to retain any value that is not explicitly replaced.