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

邮差的信 提交于 2019-12-09 05:01:38

问题


I get a error message in IE11 but not in chrome the error is:

Script1002 Syntax error

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 IE11 does not like. However it works fine in Chrome and Edge


回答1:


ie 11 not support arrow functions

try

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



回答2:


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

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



回答3:


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.

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

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


来源:https://stackoverflow.com/questions/38595690/ie-11-script1002-array-filterx-arrow-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!