_checkForMethod.js 810 B

123456789101112131415161718192021222324
  1. import _isArray from "./_isArray.js";
  2. /**
  3. * This checks whether a function has a [methodname] function. If it isn't an
  4. * array it will execute that function otherwise it will default to the ramda
  5. * implementation.
  6. *
  7. * @private
  8. * @param {Function} fn ramda implementation
  9. * @param {String} methodname property to check for a custom implementation
  10. * @return {Object} Whatever the return value of the method is.
  11. */
  12. export default function _checkForMethod(methodname, fn) {
  13. return function () {
  14. var length = arguments.length;
  15. if (length === 0) {
  16. return fn();
  17. }
  18. var obj = arguments[length - 1];
  19. return _isArray(obj) || typeof obj[methodname] !== 'function' ? fn.apply(this, arguments) : obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1));
  20. };
  21. }