forOwn.js 992 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var baseForOwn = require('./_baseForOwn'),
  2. castFunction = require('./_castFunction');
  3. /**
  4. * Iterates over own enumerable string keyed properties of an object and
  5. * invokes `iteratee` for each property. The iteratee is invoked with three
  6. * arguments: (value, key, object). Iteratee functions may exit iteration
  7. * early by explicitly returning `false`.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 0.3.0
  12. * @category Object
  13. * @param {Object} object The object to iterate over.
  14. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15. * @returns {Object} Returns `object`.
  16. * @see _.forOwnRight
  17. * @example
  18. *
  19. * function Foo() {
  20. * this.a = 1;
  21. * this.b = 2;
  22. * }
  23. *
  24. * Foo.prototype.c = 3;
  25. *
  26. * _.forOwn(new Foo, function(value, key) {
  27. * console.log(key);
  28. * });
  29. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  30. */
  31. function forOwn(object, iteratee) {
  32. return object && baseForOwn(object, castFunction(iteratee));
  33. }
  34. module.exports = forOwn;