【发布时间】:2018-04-19 16:33:47
【问题描述】:
为什么在对象中传播 undefined 会返回一个空对象? {...undefined} // equals {}:
console.log({...undefined})
为什么在数组中传播 undefined 会给你一个错误?
[...undefined] // type error:
console.log([...undefined])
【问题讨论】:
-
总结一下:对象传播等价于
Object.assign,而数组传播实际上是可迭代传播而undefined不可迭代。 -
这也是一个很好的讨论:github.com/tc39/ecma262/pull/1069
标签: javascript ecmascript-6 spread-syntax