JavaScript:Internet Explorer 不支持 Method forEach [英] JavaScript: Method forEach not supported from Internet Explorer

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

问题描述

我正在使用 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 不支持 Method forEach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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