forEachObject.js.flow 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule forEachObject
  8. * @typechecks
  9. */
  10. 'use strict';
  11. var hasOwnProperty = Object.prototype.hasOwnProperty;
  12. /**
  13. * Executes the provided `callback` once for each enumerable own property in the
  14. * object. The `callback` is invoked with three arguments:
  15. *
  16. * - the property value
  17. * - the property name
  18. * - the object being traversed
  19. *
  20. * Properties that are added after the call to `forEachObject` will not be
  21. * visited by `callback`. If the values of existing properties are changed, the
  22. * value passed to `callback` will be the value at the time `forEachObject`
  23. * visits them. Properties that are deleted before being visited are not
  24. * visited.
  25. *
  26. * @param {?object} object
  27. * @param {function} callback
  28. * @param {*} context
  29. */
  30. function forEachObject(object, callback, context) {
  31. for (var name in object) {
  32. if (hasOwnProperty.call(object, name)) {
  33. callback.call(context, object[name], name, object);
  34. }
  35. }
  36. }
  37. module.exports = forEachObject;