给出以下代码:
const civic = {make: 'Honda', model: 'Civic'};
function logArgs(make, model) {
console.log(make);
console.log(model)
}
我想这样做:
logArgs(...civic);
而不是:
logArgs(civic.make, civic.model);
我得到:
(index):39 Uncaught TypeError: Found non-callable @@iterator
是否有某种方法可以解构数组等对象,或者我试图做的事情是不可能的?
最佳答案
const civic = {make: 'Honda', model: 'Civic'};
function logArgs({make, model}) {
console.log(make);
console.log(model)
}
logArgs(civic)
关于javascript - 在 JS 中像数组一样解构对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57995974/