最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I don't understand about spread syntax inside objects - Stack Overflow

programmeradmin5浏览0评论

I don't understand about spread syntax inside objects.

console.log(...false) // TypeError not iterable
console.log(...1) // TypeError not iterable
console.log(...null) // TypeError not iterable
console.log(...undefined) // TypeError not iterable

I understand above codes that occurs error because of none-iterator.

But these codes are working well.

console.log({...false}) // {}
console.log({...1}) // {}
console.log({...null}) // {}
console.log({...undefined}) // {}

Please let me know why the above codes are working.

I don't understand about spread syntax inside objects.

console.log(...false) // TypeError not iterable
console.log(...1) // TypeError not iterable
console.log(...null) // TypeError not iterable
console.log(...undefined) // TypeError not iterable

I understand above codes that occurs error because of none-iterator.

But these codes are working well.

console.log({...false}) // {}
console.log({...1}) // {}
console.log({...null}) // {}
console.log({...undefined}) // {}

Please let me know why the above codes are working.

Share Improve this question edited Mar 11, 2021 at 8:58 mikemaccana 123k110 gold badges427 silver badges531 bronze badges asked Oct 30, 2020 at 6:13 kkangilkkangil 1,7464 gold badges16 silver badges27 bronze badges 1
  • 1 Prepend "use strict"; Object.defineProperty(Number.prototype, Symbol.iterator, { enumerable: false, configurable: true, writable: true, value: ({ [Symbol.iterator]: function*(){ for(let i = 0; i < Math.abs(this); ++i){ yield i * (this < 0 ? -1 : 1); } } })[Symbol.iterator] }); to make console.log(...1) work.
发布评论

评论列表(0)

  1. 暂无评论