1
我有一個jQuery
插件用於在IE 10和11中運行良好的web應用程序。但它在IE 7失敗。 當我調查我知道filter
方法的值是undefined
。 的代碼失敗行情況如下:JavaScript的Array的過濾方法在IE 7中不起作用
if (splitters.filter(Boolean).length === 0) {
我使用jQuery 1.8.3
我有一個jQuery
插件用於在IE 10和11中運行良好的web應用程序。但它在IE 7失敗。 當我調查我知道filter
方法的值是undefined
。 的代碼失敗行情況如下:JavaScript的Array的過濾方法在IE 7中不起作用
if (splitters.filter(Boolean).length === 0) {
我使用jQuery 1.8.3
它的JavaScript filter()
方法,它只有在IE 9+ as per the MDN documentation
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun/*, thisArg*/) {
'use strict';
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== 'function') {
throw new TypeError();
}
var res = [];
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
if (i in t) {
var val = t[i];
// NOTE: Technically this should Object.defineProperty at
// the next index, as push can be affected by
// properties on Object.prototype and Array.prototype.
// But that method's new, and collisions should be
// rare, so use the more-compatible alternative.
if (fun.call(thisArg, val, i, t)) {
res.push(val);
}
}
}
return res;
};
}