1 |
|
2 |
|
3 |
|
4 |
|
5 | if (!Array.prototype.filter)
|
6 | Array.prototype.filter = function (func, thisArg) {
|
7 | if (!((typeof func === 'Function' || typeof func === 'function') && this))
|
8 | throw new TypeError();
|
9 |
|
10 | var len = this.length >>> 0,
|
11 | res = new Array(len),
|
12 | t = this, c = 0, i = -1;
|
13 | if (thisArg === undefined)
|
14 | while (++i !== len)
|
15 |
|
16 | if (i in this)
|
17 | if (func(t[i], i, t))
|
18 | res[c++] = t[i];
|
19 | else
|
20 | while (++i !== len)
|
21 |
|
22 | if (i in this)
|
23 | if (func.call(thisArg, t[i], i, t))
|
24 | res[c++] = t[i];
|
25 |
|
26 | res.length = c;
|
27 | return res;
|
28 | }; |
\ | No newline at end of file |