8
0

isFunction.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import isObject from './isObject';
  2. /** `Object#toString` result references. */
  3. var funcTag = '[object Function]';
  4. /** Used for native method references. */
  5. var objectProto = Object.prototype;
  6. /**
  7. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  8. * of values.
  9. */
  10. var objToString = objectProto.toString;
  11. /**
  12. * Checks if `value` is classified as a `Function` object.
  13. *
  14. * @static
  15. * @memberOf _
  16. * @category Lang
  17. * @param {*} value The value to check.
  18. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  19. * @example
  20. *
  21. * _.isFunction(_);
  22. * // => true
  23. *
  24. * _.isFunction(/abc/);
  25. * // => false
  26. */
  27. function isFunction(value) {
  28. // The use of `Object#toString` avoids issues with the `typeof` operator
  29. // in older versions of Chrome and Safari which return 'function' for regexes
  30. // and Safari 8 which returns 'object' for typed array constructors.
  31. return isObject(value) && objToString.call(value) == funcTag;
  32. }
  33. export default isFunction;