<分区>
因此在解构函数默认值的 MDN 文档中,它给出了以下示例。
function drawES2015Chart({size = 'big', cords = {x: 0, y: 0}, radius =
25} = {}) {
console.log(size, cords, radius);
// do some chart drawing
}
drawES2015Chart({
cords: {x: 18, y: 30},
radius: 30
});
不过,我可以将第一行作为 function drawES2015Chart({size = 'big', cords = {x: 0, y: 0}, radius =
25})
因此省略了 ={}
部分。我不确定为什么会这样,如果较短的形式实际上同样正确,那么使用较长形式的优势是什么。