JavaScript:Internet Explorer不支持每个方法 [英] JavaScript: Method forEach not supported from Internet Explorer

查看:92
本文介绍了JavaScript:Internet Explorer不支持每个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gzip算法的javascript实现,它适用于Firefox和Chrome。但是使用Internet Explorer我收到以下错误:

I'm using a javascript implementation of the gzip algorithm which works fine with Firefox and Chrome. But with Internet Explorer I got the following error:


不支持方法forEach!

Method forEach is not supported!

代码:

deflate.deflate(data, level).forEach(function (byte) {
    putByte(byte, out);
});

我正在使用Internet Explorer 9,它应该支持forEach方法。

I'm using Internet Explorer 9, which should support the forEach Method.

任何想法?

非常感谢!

推荐答案

您可以尝试为不支持 foreach 的浏览器扩展 Array 对象这里建议的方法 Array.forEach

You might try and extend the Array object for browsers that don't support the foreach method on it as suggested here Array.forEach

一个例子是:

if (!Array.prototype.forEach) {
    Array.prototype.forEach = function(fn, scope) {
        for(var i = 0, len = this.length; i < len; ++i) {
            fn.call(scope, this[i], i, this);
        }
    }
}

这篇关于JavaScript:Internet Explorer不支持每个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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