-
Notifications
You must be signed in to change notification settings - Fork 12
/
shim.js
69 lines (58 loc) · 1.29 KB
/
shim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
if (! Array.prototype.every) {
Array.prototype.every = function (callback, context) {
var l = this.length >>> 0;
var t = Object(this);
var keepGoing = true;
for (var i = 0; i < l; i ++) {
if (i in t) {
keepGoing = callback.call(context, this[i], i, this);
if (! keepGoing) {
return keepGoing;
}
}
}
return keepGoing;
};
}
if (! Array.prototype.filter) {
Array.prototype.filter = function (callback, context) {
var l = this.length >>> 0;
var t = Object(this);
var newArray = [];
for (var i = 0; i < l; i ++) {
if (i in t) {
var elem = this[i]; // In case the callback changes it
if (callback.call(context, elem, i, this)) {
newArray.push(elem);
}
}
}
return newArray;
};
}
if (! Array.prototype.some) {
Array.prototype.some = function (callback, context) {
var l = this.length >>> 0;
var t = Object(this);
for (var i = 0; i < l; i ++) {
if (i in t) {
if (callback.call(context, this[i], i, this)) {
return true;
}
}
}
return false;
};
}
if (! Array.prototype.forEach) {
Array.prototype.forEach = function (callback, context) {
var l = this.length >>> 0;
var t = Object(this);
for (var i = 0; i < l; i ++) {
if (i in t) {
callback.call(context, this[i], i, this);
}
}
};
}