each.js 464 B

1234567891011121314151617181920
  1. var isArray = require('./isArray')
  2. var arrayEach = require('./arrayEach')
  3. var objectEach = require('./objectEach')
  4. /**
  5. * 迭代器
  6. *
  7. * @param {Object} obj 对象/数组
  8. * @param {Function} iterate(item, index, obj) 回调
  9. * @param {Object} context 上下文
  10. * @return {Object}
  11. */
  12. function each (obj, iterate, context) {
  13. if (obj) {
  14. return (isArray(obj) ? arrayEach : objectEach)(obj, iterate, context)
  15. }
  16. return obj
  17. }
  18. module.exports = each