diff --git a/core/lib_polyfill.js b/core/lib_polyfill.js index f2c8352..e0ae3af 100644 --- a/core/lib_polyfill.js +++ b/core/lib_polyfill.js @@ -133,44 +133,15 @@ /************************* ARRAY *************************/ - if (!Array.prototype.filter) { - Array.prototype.filter = function(func, thisArg) { - 'use strict'; - if (!((typeof func === 'Function' || typeof func === 'function') && this)) - throw new TypeError(); - - var len = this.length >>> 0, - res = new Array(len), // preallocate array - t = this, - c = 0, - i = -1; - - var kValue; - if (thisArg === undefined) { - while (++i !== len) { - // checks to see if the key was set - if (i in this) { - kValue = t[i]; // in case t is changed in callback - if (func(t[i], i, t)) { - res[c++] = kValue; - } - } - } - } else { - while (++i !== len) { - // checks to see if the key was set - if (i in this) { - kValue = t[i]; - if (func.call(thisArg, t[i], i, t)) { - res[c++] = kValue; - } - } - } - } - - res.length = c; // shrink down array to proper size - return res; - }; + Array.prototype.filter = function(fn) { + var a = []; + for (var i = 0; i < this.length; i++) { + var n = fn(this[i]); + if (n) { + a.push(this[i]); + } + } + return a; } @@ -461,4 +432,4 @@ }()); } - \ No newline at end of file +