仅在IE中用于箭头表示法的语法错误

时间:2017-01-17 17:26:38

标签: javascript internet-explorer

我一直在使用这行代码来匹配这两个数组,因此它们具有相同数量的数据。

var items = viewModel.Date1;
var items2 = viewModel.Date2;            
items = items2.map( row =>

    //is there a matching row in items?
    items.filter( r => r.theString == row.theString).length ==  0 ?

    //if not, fill with zeros
    {theString:0, theCount:0} :

    //if there is, return the items' row
    items.filter( r => r.theString == row.theString)[0] );

在IE中,使用=>会给我一个语法错误。

如何重写此内容以便在Firefox,Chrome和IE中使用?

2 个答案:

答案 0 :(得分:2)

http://caniuse.com/#feat=arrow-functions

箭头功能尚未在IE中使用。

您最好通过像Babel,http://babeljs.io/

这样的JS编译器来运行代码

答案 1 :(得分:1)

箭头功能

r => r.theString == row.theString[0]  

更改为

function(r) { r.theString == row.theString[0] }
相关问题