forked from gnab/remark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfills.js
45 lines (34 loc) · 819 Bytes
/
polyfills.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
exports.apply = function () {
forEach([Array, window.NodeList, window.HTMLCollection], extend);
};
function forEach (list, f) {
var i;
for (i = 0; i < list.length; ++i) {
f(list[i], i);
}
}
function extend (object) {
var prototype = object && object.prototype;
if (!prototype) {
return;
}
prototype.forEach = prototype.forEach || function (f) {
forEach(this, f);
};
prototype.filter = prototype.filter || function (f) {
var result = [];
this.forEach(function (element) {
if (f(element, result.length)) {
result.push(element);
}
});
return result;
};
prototype.map = prototype.map || function (f) {
var result = [];
this.forEach(function (element) {
result.push(f(element, result.length));
});
return result;
};
}