Javascript IE 11 Script1002 Array.Filter(x => ...)(箭头函数)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38595690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:38:20  来源:igfitidea点击:

IE 11 Script1002 Array.Filter(x => ...) (Arrow functions)

javascriptecmascript-6internet-explorer-11

提问by MicroMan

I get a error message in IE11but not in chrome the error is:

我在IE11 中收到一条错误消息,但在 chrome 中没有,错误是:

Script1002 Syntax error

Script1002 语法错误

My code is as follows

我的代码如下

var selectedRoles = vm.roles.filter(x => x.id === role.id);

The line and column number of the error suggest that it is the arrow function =>that IE11does not like. However it works fine in Chromeand Edge

错误的行和列数表明,它是箭头功能=>IE11不喜欢。但是它在ChromeEdge 中运行良好

回答by Grundy

ie 11 not support arrow functions

即 11 不支持箭头函数

try

尝试

var selectedRoles = vm.roles.filter(function(x) { return x.id === role.id; });

回答by Pranav C Balan

IE not supported arrow functioncheck browser compatibility here. If you want IE support then use the normal function instead.

IE 不支持箭头功能在这里检查浏览器兼容性。如果您想要 IE 支持,请改用普通功能。

var selectedRoles = vm.roles.filter(function(x) {
  return x.id === role.id
});

回答by Ayan

The arrow function is not supported yet in IE 11. You can refer to these compatibity table: https://kangax.github.io/compat-table/es6/to get an overview what is suuported where and to what extent in a detailed fashion.

IE 11 尚不支持箭头功能。您可以参考这些兼容性表:https: //kangax.github.io/compat-table/es6/ 以详细了解支持的内容和支持的范围时尚。

Use pollyfills or a PRE-ES6 compatible code, e.g.

使用 pollyfills 或 PRE-ES6 兼容代码,例如

var selectedRoles = vm.roles.filter(function(x) {
   return x.id === role.id
});