let statement in loop doesn't work as expected in IE

一世执手 提交于 2019-12-10 22:00:05

问题


I am trying some example in ECMAScript 6. That is working differently compared to other browsers. This returns true in Firefox, but it returns false in IE. Why is this working different in 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);

回答1:


According to caniuse.com IE11 kind of supports let:

let variables are not bound separately to each iteration of for loops



来源:https://stackoverflow.com/questions/39159669/let-statement-in-loop-doesnt-work-as-expected-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!