createChainedFunction.js 598 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = createChainedFunction;
  6. /**
  7. * Safe chained function
  8. *
  9. * Will only create a new function if needed,
  10. * otherwise will pass back existing functions or null.
  11. *
  12. * @returns {function|null}
  13. */
  14. function createChainedFunction() {
  15. var args = [].slice.call(arguments, 0);
  16. if (args.length === 1) {
  17. return args[0];
  18. }
  19. return function chainedFunction() {
  20. for (var i = 0; i < args.length; i++) {
  21. if (args[i] && args[i].apply) {
  22. args[i].apply(this, arguments);
  23. }
  24. }
  25. };
  26. }