lastEach.js 518 B

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