is-arguments.js 724 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. var getClass = require("./get-class");
  3. /**
  4. * @name samsam.isArguments
  5. * @param Object object
  6. *
  7. * Returns ``true`` if ``object`` is an ``arguments`` object,
  8. * ``false`` otherwise.
  9. */
  10. function isArguments(object) {
  11. if (getClass(object) === "Arguments") {
  12. return true;
  13. }
  14. if (
  15. typeof object !== "object" ||
  16. typeof object.length !== "number" ||
  17. getClass(object) === "Array"
  18. ) {
  19. return false;
  20. }
  21. if (typeof object.callee === "function") {
  22. return true;
  23. }
  24. try {
  25. object[object.length] = 6;
  26. delete object[object.length];
  27. } catch (e) {
  28. return true;
  29. }
  30. return false;
  31. }
  32. module.exports = isArguments;