forEachObject.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. * @typechecks
  8. */
  9. 'use strict';
  10. var hasOwnProperty = Object.prototype.hasOwnProperty;
  11. /**
  12. * Executes the provided `callback` once for each enumerable own property in the
  13. * object. The `callback` is invoked with three arguments:
  14. *
  15. * - the property value
  16. * - the property name
  17. * - the object being traversed
  18. *
  19. * Properties that are added after the call to `forEachObject` will not be
  20. * visited by `callback`. If the values of existing properties are changed, the
  21. * value passed to `callback` will be the value at the time `forEachObject`
  22. * visits them. Properties that are deleted before being visited are not
  23. * visited.
  24. *
  25. * @param {?object} object
  26. * @param {function} callback
  27. * @param {*} context
  28. */
  29. function forEachObject(object, callback, context) {
  30. for (var name in object) {
  31. if (hasOwnProperty.call(object, name)) {
  32. callback.call(context, object[name], name, object);
  33. }
  34. }
  35. }
  36. module.exports = forEachObject;