google-chrome - 语法错误 : missing = in const declaration Firefox 50

标签 google-chrome firefox ecmascript-6 constants

我有一个如下所示的循环:

const bar = {a: 1, b: 2}
for (const k in bar) { //Throws in Firefox but not Chrome 54
    console.log(k)
}

这是一个错误吗?或者规范中的灰色区域?

最佳答案

是的,这似乎是 Firefox 中的一个错误。 spec allows the use of const :

IterationStatement:
    for(ForDeclaration in Expression) Statement

ForDeclaration:
    LetOrConst ForBinding

ForBinding:
    BindingIdentifier
    BindingPattern

(截断和简化)

似乎 Firefox 错误地将 ForDeclaration 解释为 LexicalBinding .

相关:ECMAScript 2015: const in for loops

这似乎是这个问题的错误报告:https://bugzilla.mozilla.org/show_bug.cgi?id=1101653 .

正确 letconst即将登陆 Firefox:https://twitter.com/evilpies/status/768881995912994816

关于google-chrome - 语法错误 : missing = in const declaration Firefox 50,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39044803/

相关文章:

javascript - 如何使用 Javascript 或 C# 禁用 Chrome 浏览器的打印预览功能

java - 为什么 https ://username:password@example. com 不起作用?

javascript - 尽管 super 调用, super 类属性仍未定义

css - 无法覆盖用户代理样式表中的边框间距

javascript - Chrome 扩展程序中弹出窗口关闭后记住数组

javascript - Firefox 插件 console.log() 不工作

javascript - 如何循环表单输入并在 react 中获取值

javascript - 如何向 mousemove 事件添加一些缓冲区,以便它不会中断 mouseup 事件

javascript - 如何从 Angular 4 中的 chrome.runtime.sendMessage 获取回调?

html - CSS 动画在 Chrome 中有效,但在 Firefox 和 Safari 中无效