Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript "for of" fails in IE 11

I have the following bit of code to select and remove a d3.js node.

 if (d.children) {
        for (var child of d.children) {
            if (child == node) {
                d.children = _.without(d.children, child);
                update(root);
                break;
            }
        }
    }

This works fine in Chrome and Edge, but fails in IE-11 with missing ;. It appears to be a problem with using 'of' to loop. Has anyone else run across this issue with IE before and if so how did you resolve it?

like image 923
Michael McCurley Avatar asked Sep 23 '16 22:09

Michael McCurley


People also ask

Does IE 11 support JavaScript?

Internet Explorer 11 doesn't support JavaScript versions later than ES5. If you want to use the syntax and features of ECMAScript 2015 or later, or TypeScript, you have two options as described in this article. You can also combine these two techniques.

Does Const work in IE11?

Browser Compatibility #let and const work in all modern browsers, and IE11 and up.

Why JavaScript is not working in Internet Explorer?

Internet Explorer When the "Internet Options" window opens, select the Security tab. On the "Security" tab, make sure the Internet zone is selected, and then click on the "Custom level..." button. In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section.


1 Answers

This is an ES2015 (also know as ES6) feature and only supported in modern browsers. Generally you would only use this construct together with a transpiler like babel in order to support older browsers.

You can see the compatibility table for the for...of statement here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of

like image 166
Willem D'Haeseleer Avatar answered Sep 20 '22 02:09

Willem D'Haeseleer