我正在使用JavaScript实现的gzip算法,它在Firefox和Chrome上运行良好。但是,在Internet Explorer中我遇到了以下错误:
不支持forEach方法!
代码:
deflate.deflate(data, level).forEach(function (byte) {
putByte(byte, out);
});
我正在使用支持forEach方法的Internet Explorer 9浏览器。
有什么建议吗?
非常感谢!
我正在使用JavaScript实现的gzip算法,它在Firefox和Chrome上运行良好。但是,在Internet Explorer中我遇到了以下错误:
不支持forEach方法!
代码:
deflate.deflate(data, level).forEach(function (byte) {
putByte(byte, out);
});
我正在使用支持forEach方法的Internet Explorer 9浏览器。
有什么建议吗?
非常感谢!
你可以尝试扩展Array
对象,以便在不支持其forEach
方法的浏览器中使用,如此处建议的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);
}
}
}
在IE9中不支持forEach,您可以尝试使用jQuery。
例如:
$. each (function (byte) {
putByte(byte, out);
});
.forEach()
仅在标准模式下受支持。deflate.deflate()
是否总是返回一个数组? - nnnnnnfor
循环替换forEach
部分。 - RobG