Destructuring assignment in generator expressions and array comprehensions

Why does `for ([] in object);` work fine but `[void 0 for ([] in object)]` or `(void 0 for ([] in object))` throw a syntax error for invalid left-hand assignment? For example, I would expect the following code to work, but it doesn't (the assertion isn't even done due to the syntax error): let ( i = 0, iterable = {__iterator__:function() { var i = 5; while (i--) yield i; } } ) { for ([] in iterable) i++; console.assertEquals([void 0 for ([] in iterable)].length, i); }
My guess is that they hit different grammar rules: the first for is NOT a generator (it is a for-statement), while the latter is. It doesn't appear that decomposition is supported in that position.

以上就是Destructuring assignment in generator expressions and array comprehensions的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准