拡散と破壊は異なった働きをしますが、どちらも同様の仕事をしているようです。彼らはなぜ異なっているのですか?ただ1つだけを使用してみませんか?似たような仕事をしているように見えるにもかかわらず、拡散と破壊が異なる理由
let foo = [1,2,3];
let [o,t,th] = foo; //destructing works
let [o,t,th] = ...foo; // spreading doesn't work. will not compile
function test (a,b,c) {
console.log(`${a}, ${b}, ${c}`)
}
test(...foo); //works but is sort of destructinng foo into a,b,c
test(foo) //assigns foo to a. b and c are undefined.
「foo」とは何ですか? – klugjo
oops 'let [o、t、th] = [... foo]でなければなりません:let foo = [1,2,3]; ' –
' ; ' – talentedandrew