[removed] Method forEach not supported from Intern

2020-02-11 03:11发布

问题:

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:

Method forEach is not supported!

Code:

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

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

Any ideas?

Thank you very much!

回答1:

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

One example is:

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);
        }
    }
}


回答2:

forEach is not supported in IE9, you can try using jquery.
ex:

$. each (function (byte) {
  putByte(byte, out);
});