0

I am having an issue in Internet Explorer 11 vs. Google Chrome.

The following code works in Chrome but does not seem to work in IE 11 with the familiar problem that the scope of the func(i) will always be 4, whereas in chrome it assigns the "i" value properly.

for (let i = 0; i < 5; i++) {
var select = document.getElementById("Select" + i);
select.addEventListener("change", function() {
func(i);
} ;

}

function func(num) {
console.log(num);
}

What is a quick workaround/conversion tactic for this as I have a lot of code that depends on the let statement working properly and would like to minimize revisions. Thanks.

IntegrateThis
  • 853
  • 2
  • 16
  • 39
  • Chrome is doing it properly. But until IE fixes the bug, this is the same as [JavaScript closure inside loops – simple practical example](http://stackoverflow.com/q/750486/1529630) – Oriol Aug 16 '16 at 17:09
  • @Oriol wrapping in another function is also not working in IE. – IntegrateThis Aug 16 '16 at 17:11
  • You must be doing it wrong. An IIFE works perfectly. – Oriol Aug 16 '16 at 17:20

0 Answers0