I have experienced a problem on a page under IE11, which crashes a page there. The problematic code essentially takes a String dynamically from the server, initializes a variable with that and later uses it as object key. To make the question digestible, I have written a small script:
var bar = "b";
var foo = {[bar]: "Orson oson a borsos borsós fosos koros boros korsón"};
This works under Chrome, FireFox and Microsoft Edge alike, but under IE11, I get the following error:
Expected identifier, string or number
Why is IE11 not allowing this and how should I solve this?
ES6orES7related. Tryvar bar = "b", foo = {}; foo[bar] = "Orson oson a borsos borsós fosos koros boros korsón";ES5but not new versions likeES6orES7. InES5you can't place a variable in key of object. Hence, the error.key = String([bar])and then use key?