function
each()
Option name | Type | Description |
---|---|---|
list | Array, NodeList, HTMLCollection, Object | |
cb | Function |
function each(list, cb) {
if (!list) {
return;
}
if (typeof cb !== 'function') {
throw new Error('Cannot invoke `each` without a callback!');
}
var i = 0;
var len = list.length;
// Object
if (len === undefined) {
for (i in list) {
if (i !== 'prototype' && list.hasOwnProperty(i)) {
cb(i, list[i]);
}
}
}
// Array-like
else {
for (; i < len; i++) {
cb(list[i]);
}
}
}
return each;
}));