我在IE中遇到语法错误,但Chrome中没有 [英] I get a syntax error in IE but not in Chrome

查看:137
本文介绍了我在IE中遇到语法错误,但Chrome中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个代码(一个函数),在谷歌Chrome / Fire Fox,但不是在IE。



我有一个名为ReadCookie的函数,它基本上只是将cookie存储到一个名为cookiearray的数组中

  function ReadCookie(){

var allcookies = document.cookie; //变量名为allcookies存储所有的cookie。
cookiearray = allcookies.split(';')。map(c => c.split('=')[1]); // cookiearray是一个将所有值作为字符串的数组。

}

IE说第四行不正确 cookiearray = allcookies.split(';')。map(c => c.split('=')[1]); 但我不知道为什么。 >

谢谢!

解决方案

我相信这是一个ECMA脚本6 事情与您使用地图的方式。



所以你可以这样写:

  cookiearray = allcookies.split ';')。map(function(c){
return c.split('=')[1];
}); // cookiearray是一个将所有值作为字符串的数组。


So I have this code (a function) that works in Google Chrome/Fire Fox but not in IE. If I comment 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!

解决方案

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.

这篇关于我在IE中遇到语法错误,但Chrome中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆