为什么Firefox在这个javascript for循环中抱怨分号?

Bry*_*ant 5 javascript firefox

所以我有一个非常基本的函数与for循环.它在现代Chrome和Firefox浏览器上运行良好,但在特别挑剔的Firefox 38浏览器上却没有.根据文档,自Firefox 13以来一直支持此功能.

function showhide_class(cl) {
  var es = document.getElementsByClassName(cl);
  for(let e of es) {
  e.style.display = (e.style.display == "block") ? "none" : "block";
  }
}
Run Code Online (Sandbox Code Playgroud)

Firefox报告的确切错误是:

SyntaxError: missing ; after for-loop initializer
Run Code Online (Sandbox Code Playgroud)

那么,为什么要报告这个错误,你知道一个解决方法吗?非常感谢.

Rei*_*ton 7

let声明是问题.请for (var e of es)改用.

根据MDN的let说法,该声明直到第44版才得到Firefox的支持.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let