【问题标题】:SyntaxError: missing = in const declaration Firefox 50SyntaxError: missing = in const 声明 Firefox 50
【发布时间】:2016-12-26 22:55:03
【问题描述】:

我有一个类似如下的循环:

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

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

【问题讨论】:

    标签: google-chrome firefox ecmascript-6 constants


    【解决方案1】:

    是的,这似乎是 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

    【讨论】:

    • 嗯,Firefox 犯了我在阅读规范时犯的同样错误。没想过要检查循环是否有特殊行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    • 2018-11-07
    相关资源
    最近更新 更多