UNPKG

959 BJavaScriptView Raw
1import baseForOwn from './_baseForOwn';
2import baseIteratee from './_baseIteratee';
3
4/**
5 * Iterates over own enumerable string keyed properties of an object invoking
6 * `iteratee` for each property. The iteratee is invoked with three arguments:
7 * (value, key, object). Iteratee functions may exit iteration early by
8 * explicitly returning `false`.
9 *
10 * @static
11 * @memberOf _
12 * @since 0.3.0
13 * @category Object
14 * @param {Object} object The object to iterate over.
15 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16 * @returns {Object} Returns `object`.
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 */
31function forOwn(object, iteratee) {
32 return object && baseForOwn(object, baseIteratee(iteratee));
33}
34
35export default forOwn;