Closed peppermit closed 4 years ago
测试 ie8 兼容性时,发现没有对 indexOf 和 forEach 这两个方法进行处理。 建议加上以下两段代码
if(!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/ ) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if(from < 0) from += len; for(; from < len; from++) { if(from in this && this[from] === elt) return from; } return -1; }; } if(!Array.prototype.forEach) { Array.prototype.forEach = function forEach(callback, thisArg) { var T, k; if(this == null) { throw new TypeError("this is null or not defined"); } var O = Object(this); var len = O.length >>> 0; if(typeof callback !== "function") { throw new TypeError(callback + " is not a function"); } if(arguments.length > 1) { T = thisArg; } k = 0; while(k < len) { var kValue; if(k in O) { kValue = O[k]; callback.call(T, kValue, k, O); } k++; } }; }
谢谢反馈,不过我们的标准版 JS 代码中没有用到这两个方法。如果有用到欢迎指出。
lib/array 下有 Polyfill,可以针对 IE8 导入使用。
测试 ie8 兼容性时,发现没有对 indexOf 和 forEach 这两个方法进行处理。 建议加上以下两段代码