IE / JS:减少对象

时间:2011-08-17 14:57:51

标签: javascript arrays internet-explorer internet-explorer-8 reduce

我的javascript应用程序非常适用于firefox和chrome。但它在Internet Explorer(IE 8)上会被破坏。

我在控制台日志中没有收到错误消息。通过调试我注意到的代码,应用程序在以下行中断:

 series.reduce(visit, []);

此时整个功能退出。 我知道,reduce适用于数组,但console.info(typeof(series))告诉:object

但是这个对象看起来像一个数组 - 它适用于FF / Chrome。 这可能是为什么IE停止处理此功能的原因? 而且:如何在IE处理这个问题?

谢谢。

2 个答案:

答案 0 :(得分:18)

IE 9之前不支持Reduce:https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/reduce#Browser_compatibility

对于不支持reduce的浏览器,该链接确实有一些代码解决方法。

答案 1 :(得分:3)

您还可以在此处找到其他ES5 JavaScript数组函数polyfills:

http://tech.pro/tutorial/1834/working-with-es5-javascript-array-functions-in-modern-and-legacy-browsers#indexof