首页 > `let is a reserved identifier` 异常谁人知?

`let is a reserved identifier` 异常谁人知?

在Firefox v40.0.3 版本执行 包含 let关键字的语句, 抛出异常:let is a reserved identifier, Firefox 对ES2015规范中的 let 是支持的啊, 这是为毛啊? 求教!!!

异常信息如下图所示:


MDN文档:

Firefox-specific notes
Only available to code blocks in HTML wrapped in a <script type="application/javascript;version=1.7"> block (or higher version). Beware, however, that as this is a non-standard feature, this will most likely break support for other browsers. XUL script tags have access to these features without needing this special block. See bug 932517 and bug 932513.
Support in Worker code is hidden behind the dom.workers.latestJSVersion flag. bug 487070
ES6 compliance for let in SpIderMonkey is tracked in bug 950547 and non-standard extensions are going to be removed in the future bug 1023609.


<html>
<head>
<script type="application/javascript;version=1.7">
function test(){
    if(true){
        let a = '1';
        console.log(a);
    }
}
</script>
</head>
<body>
<input type="button" value="test" onclick="test">
</body>

亲自测试过了,加上version=1.7就可以了,不需要use strict


虽然最新版的火狐浏览器已经支持ES2015,但还是要声明为严格模式才可以使用。

var foo = function() {
    "use strict";
    for (let i = 0; i < 5; i++) {
        console.log(i);
    }
};
foo();
【热门文章】
【热门文章】