1 | /**
|
2 | * each : each(list, fn)
|
3 | * Iterates through `list` (an array or an object). This is useful when dealing
|
4 | * with NodeLists like `document.querySelectorAll`.
|
5 | */
|
6 |
|
7 | function each (list, fn) {
|
8 | if (!list) return
|
9 |
|
10 | var i
|
11 | var len = list.length
|
12 | var idx
|
13 |
|
14 | if (typeof len === 'number') {
|
15 | if (each.native) return each.native.call(list, fn)
|
16 | for (i = 0; i < len; i++) fn(list[i], i, i)
|
17 | } else {
|
18 | idx = 0
|
19 | for (i in list) {
|
20 | if (list.hasOwnProperty(i)) fn(list[i], i, idx++)
|
21 | }
|
22 | }
|
23 |
|
24 | return list
|
25 | }
|
26 |
|
27 | each.native = Array.prototype.forEach
|
28 |
|
29 | module.exports = each
|