admin管理员组文章数量:1026989
So I have this code (a function) that works in Google Chrome/Fire Fox but not in IE. If I ment this certain line, everything runs fine, except that line is crucial.
I have this function called ReadCookie, which basically just stores the cookies into an array called cookiearray.
function ReadCookie() {
var allcookies = document.cookie; //variable called "allcookies" stores all the cookies.
cookiearray = allcookies.split(';').map(c => c.split('=')[1]); //cookiearray is an array that has all the values as strings.
}
IE said that the 4th line is incorrect cookiearray = allcookies.split(';').map(c => c.split('=')[1]);
but I don't know why.
Thanks!
So I have this code (a function) that works in Google Chrome/Fire Fox but not in IE. If I ment this certain line, everything runs fine, except that line is crucial.
I have this function called ReadCookie, which basically just stores the cookies into an array called cookiearray.
function ReadCookie() {
var allcookies = document.cookie; //variable called "allcookies" stores all the cookies.
cookiearray = allcookies.split(';').map(c => c.split('=')[1]); //cookiearray is an array that has all the values as strings.
}
IE said that the 4th line is incorrect cookiearray = allcookies.split(';').map(c => c.split('=')[1]);
but I don't know why.
Thanks!
Share Improve this question asked Jun 11, 2016 at 22:39 EdwinEdwin 4001 gold badge5 silver badges19 bronze badges 2- 1 you could also try a syntax from some future ES7 working draft for instance. If you really want your production code to work - you'll stick to using a standard JS syntax and methods instead. – Bekim Bacaj Commented Jun 11, 2016 at 22:50
- @BekimBacaj Or using a transpiler.. :D – user2864740 Commented Jun 11, 2016 at 23:01
3 Answers
Reset to default 4Arrow functions (like c => c.split('=')[1]
) are a new feature in ES6. Chrome supports them. Internet Explorer does not.
I believe it's an ECMA script 6 thing with the way you're using the map.
So you can write it like this instead:
cookiearray = allcookies.split(';').map(function (c) {
return c.split('=')[1];
}); //cookiearray is an array that has all the values as strings.
The solution I implemented was as follows
goto: https://babeljs.io/repl
Paste in your code and select es2015.
In your new code paste the following, if you are using forEach (which is again not supported in IE) :
if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = Array.prototype.forEach; }
Use indexOf instead of includes
So I have this code (a function) that works in Google Chrome/Fire Fox but not in IE. If I ment this certain line, everything runs fine, except that line is crucial.
I have this function called ReadCookie, which basically just stores the cookies into an array called cookiearray.
function ReadCookie() {
var allcookies = document.cookie; //variable called "allcookies" stores all the cookies.
cookiearray = allcookies.split(';').map(c => c.split('=')[1]); //cookiearray is an array that has all the values as strings.
}
IE said that the 4th line is incorrect cookiearray = allcookies.split(';').map(c => c.split('=')[1]);
but I don't know why.
Thanks!
So I have this code (a function) that works in Google Chrome/Fire Fox but not in IE. If I ment this certain line, everything runs fine, except that line is crucial.
I have this function called ReadCookie, which basically just stores the cookies into an array called cookiearray.
function ReadCookie() {
var allcookies = document.cookie; //variable called "allcookies" stores all the cookies.
cookiearray = allcookies.split(';').map(c => c.split('=')[1]); //cookiearray is an array that has all the values as strings.
}
IE said that the 4th line is incorrect cookiearray = allcookies.split(';').map(c => c.split('=')[1]);
but I don't know why.
Thanks!
Share Improve this question asked Jun 11, 2016 at 22:39 EdwinEdwin 4001 gold badge5 silver badges19 bronze badges 2- 1 you could also try a syntax from some future ES7 working draft for instance. If you really want your production code to work - you'll stick to using a standard JS syntax and methods instead. – Bekim Bacaj Commented Jun 11, 2016 at 22:50
- @BekimBacaj Or using a transpiler.. :D – user2864740 Commented Jun 11, 2016 at 23:01
3 Answers
Reset to default 4Arrow functions (like c => c.split('=')[1]
) are a new feature in ES6. Chrome supports them. Internet Explorer does not.
I believe it's an ECMA script 6 thing with the way you're using the map.
So you can write it like this instead:
cookiearray = allcookies.split(';').map(function (c) {
return c.split('=')[1];
}); //cookiearray is an array that has all the values as strings.
The solution I implemented was as follows
goto: https://babeljs.io/repl
Paste in your code and select es2015.
In your new code paste the following, if you are using forEach (which is again not supported in IE) :
if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = Array.prototype.forEach; }
Use indexOf instead of includes
本文标签: javascriptI get a syntax error in IE but not in ChromeStack Overflow
版权声明:本文标题:javascript - I get a syntax error in IE but not in Chrome - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745666394a2162201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论