emptyFunction.js 959 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. /**
  3. * Copyright (c) 2013-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. *
  9. */
  10. function makeEmptyFunction(arg) {
  11. return function () {
  12. return arg;
  13. };
  14. }
  15. /**
  16. * This function accepts and discards inputs; it has no side effects. This is
  17. * primarily useful idiomatically for overridable function endpoints which
  18. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  19. */
  20. var emptyFunction = function emptyFunction() {};
  21. emptyFunction.thatReturns = makeEmptyFunction;
  22. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  23. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  24. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  25. emptyFunction.thatReturnsThis = function () {
  26. return this;
  27. };
  28. emptyFunction.thatReturnsArgument = function (arg) {
  29. return arg;
  30. };
  31. module.exports = emptyFunction;