简体   繁体   中英

Typescript for (let i of someArray) doesn't work in IE11

Does anyone know why, in TypeScript with a compilerOptions targeting ES6, I used the following syntax to iterate the array? It worked on both Edge and Chrome, but not IE11. It complained a; is missing on the beginning line of the for loop.

 for (let thisId of changedIDs) {... }

When I changed it to the plain old Javascript for loop, then it worked on all 3 browsers.

 for (var i = 0; i < changedAnswerIDs.length; i++) {... }

The issue is with the for...of loop. IE has limited support for ES6 syntax. As @Phix mentioned in the comment, you should change the compiler target to ES5 or earlier to support IE.

IE 11 doesn't fully support ES6. You can use Babel to compile to ES5. Babel: https://babeljs.io/ or any other compiler really. You can also use this link to see more about compatibility: http://kangax.github.io/compat-table/es6/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM