我听说...两者都称为"传播语法 "和"传播运算符 ",后者更受欢迎.相关MDN文档的URL 表明它最初被称为扩展运算符,但后来改为扩展语法,MDN的运算符列表没有提到它.
Google似乎认为术语运营商更受欢迎并被接受,其中包括Microsoft文档和es6-features.org等网站.
哪个术语在ECMAScript的上下文中最正确,如果有的话,为什么?数组解构赋值怎么样?
我不了解对象内的传播语法。
console.log(...false) // TypeError not iterable
console.log(...1) // TypeError not iterable
console.log(...null) // TypeError not iterable
console.log(...undefined) // TypeError not iterable
Run Code Online (Sandbox Code Playgroud)
我理解上面的代码由于非迭代器而发生错误。
但是这些代码运行良好。
console.log({...false}) // {}
console.log({...1}) // {}
console.log({...null}) // {}
console.log({...undefined}) // {}
Run Code Online (Sandbox Code Playgroud)
请让我知道为什么上述代码有效。