isFunction.js 993 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var baseGetTag = require('./_baseGetTag'),
  2. isObject = require('./isObject');
  3. /** `Object#toString` result references. */
  4. var asyncTag = '[object AsyncFunction]',
  5. funcTag = '[object Function]',
  6. genTag = '[object GeneratorFunction]',
  7. proxyTag = '[object Proxy]';
  8. /**
  9. * Checks if `value` is classified as a `Function` object.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 0.1.0
  14. * @category Lang
  15. * @param {*} value The value to check.
  16. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  17. * @example
  18. *
  19. * _.isFunction(_);
  20. * // => true
  21. *
  22. * _.isFunction(/abc/);
  23. * // => false
  24. */
  25. function isFunction(value) {
  26. if (!isObject(value)) {
  27. return false;
  28. }
  29. // The use of `Object#toString` avoids issues with the `typeof` operator
  30. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  31. var tag = baseGetTag(value);
  32. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  33. }
  34. module.exports = isFunction;