小编Raa*_*nan的帖子

循环中的 let 语句在 IE 中无法按预期工作

我正在尝试 ECMAScript 6 中的一些示例。与其他浏览器相比,它的工作方式不同。这true在 Firefox 中返回,但false在 IE 中返回。为什么这在 Internet Explorer 中的工作方式不同?

let callbacks = []
for (let i = 0; i <= 2; i++) {
  callbacks[i] = function () { console.log(i); return i * 2 }
}
console.log(callbacks[0]() === 0);
console.log(callbacks[1]() === 2);
console.log(callbacks[2]() === 4);
Run Code Online (Sandbox Code Playgroud)

javascript internet-explorer let ecmascript-6

6
推荐指数
1
解决办法
4549
查看次数

标签 统计

ecmascript-6 ×1

internet-explorer ×1

javascript ×1

let ×1