最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ecmascript 6 - Javascript "for of" fails in IE 11 - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Sep 24, 2016 at 18:02 altocumulus 21.6k13 gold badges64 silver badges86 bronze badges asked Sep 23, 2016 at 22:26 Michael McCurleyMichael McCurley 1931 gold badge2 silver badges8 bronze badges 2
  • 1 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… note the browser compatibility – Kevin B Commented Sep 23, 2016 at 22:31
  • Is there a reason you can't use for..in? – maurycy Commented Sep 24, 2016 at 12:50
Add a comment  | 

1 Answer 1

Reset to default 19

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

发布评论

评论列表(0)

  1. 暂无评论