This question already has answers here:
ES6 destructuring function parameter - naming root object
(3个答案)
10天前关闭。
都
和
是可能的。那这样的东西呢?
(3个答案)
10天前关闭。
都
function x(o) {
return o.a + o.b
}
和
function x({ a, b }) {
return a + b
}
是可能的。那这样的东西呢?
function x(o | { a, b }) {
console.log('Whole thing:', o)
return a + b
}
最佳答案
您可以在函数内部移动解构部分。
function x(o) {
const { a, b } = o;
console.log('Whole thing:', o)
return a + b;
}