isFunction.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var isObject = require('./isObject');
  2. /** `Object#toString` result references. */
  3. var funcTag = '[object Function]',
  4. genTag = '[object GeneratorFunction]';
  5. /** Used for built-in method references. */
  6. var objectProto = Object.prototype;
  7. /**
  8. * Used to resolve the
  9. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10. * of values.
  11. */
  12. var objectToString = objectProto.toString;
  13. /**
  14. * Checks if `value` is classified as a `Function` object.
  15. *
  16. * @static
  17. * @memberOf _
  18. * @since 0.1.0
  19. * @category Lang
  20. * @param {*} value The value to check.
  21. * @returns {boolean} Returns `true` if `value` is correctly classified,
  22. * else `false`.
  23. * @example
  24. *
  25. * _.isFunction(_);
  26. * // => true
  27. *
  28. * _.isFunction(/abc/);
  29. * // => false
  30. */
  31. function isFunction(value) {
  32. // The use of `Object#toString` avoids issues with the `typeof` operator
  33. // in Safari 8 which returns 'object' for typed array and weak map constructors,
  34. // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  35. var tag = isObject(value) ? objectToString.call(value) : '';
  36. return tag == funcTag || tag == genTag;
  37. }
  38. module.exports = isFunction;