2016-06-09 6 views
1

Une méthode de filtration de matrice de JavaScript ne fonctionne pas je utiliser un plugin jQuery utilisé dans l'application web qui fonctionne bien dans IE et 11. Mais il a échoué en IE 7. Quand j'étudie, j'ai appris que la valeur de la méthode filter est undefined. La ligne de code est échoue comme suit:dans IE 7

if (splitters.filter(Boolean).length === 0) { 

J'utilise jQuery 1.8.3

Répondre

1

Il est la méthode JavaScript filter(), il est pris en charge que dans IE 9+ as per the MDN documentation


Check polyfill option from MDN for older browser.

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