someObject.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. *
  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 until it finds one where callback returns a truthy value. If such a
  15. * property is found, `someObject` immediately returns true. Otherwise, it
  16. * returns false.
  17. *
  18. * The `callback` is invoked with three arguments:
  19. *
  20. * - the property value
  21. * - the property name
  22. * - the object being traversed
  23. *
  24. * Properties that are added after the call to `someObject` will not be
  25. * visited by `callback`. If the values of existing properties are changed, the
  26. * value passed to `callback` will be the value at the time `someObject`
  27. * visits them. Properties that are deleted before being visited are not
  28. * visited.
  29. */
  30. function someObject(object, callback, context) {
  31. for (var name in object) {
  32. if (hasOwnProperty.call(object, name)) {
  33. if (callback.call(context, object[name], name, object)) {
  34. return true;
  35. }
  36. }
  37. }
  38. return false;
  39. }
  40. module.exports = someObject;