isArguments.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var isArrayLikeObject = require('./isArrayLikeObject');
  2. /** `Object#toString` result references. */
  3. var argsTag = '[object Arguments]';
  4. /** Used for built-in method references. */
  5. var objectProto = Object.prototype;
  6. /** Used to check objects for own properties. */
  7. var hasOwnProperty = objectProto.hasOwnProperty;
  8. /**
  9. * Used to resolve the
  10. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  11. * of values.
  12. */
  13. var objectToString = objectProto.toString;
  14. /** Built-in value references. */
  15. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  16. /**
  17. * Checks if `value` is likely an `arguments` object.
  18. *
  19. * @static
  20. * @memberOf _
  21. * @since 0.1.0
  22. * @category Lang
  23. * @param {*} value The value to check.
  24. * @returns {boolean} Returns `true` if `value` is correctly classified,
  25. * else `false`.
  26. * @example
  27. *
  28. * _.isArguments(function() { return arguments; }());
  29. * // => true
  30. *
  31. * _.isArguments([1, 2, 3]);
  32. * // => false
  33. */
  34. function isArguments(value) {
  35. // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  36. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  37. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  38. }
  39. module.exports = isArguments;