classof.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. var TO_STRING_TAG_SUPPORT = require('../internals/to-string-tag-support');
  2. var isCallable = require('../internals/is-callable');
  3. var classofRaw = require('../internals/classof-raw');
  4. var wellKnownSymbol = require('../internals/well-known-symbol');
  5. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  6. var $Object = Object;
  7. // ES3 wrong here
  8. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
  9. // fallback for IE11 Script Access Denied error
  10. var tryGet = function (it, key) {
  11. try {
  12. return it[key];
  13. } catch (error) { /* empty */ }
  14. };
  15. // getting tag from ES6+ `Object.prototype.toString`
  16. module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
  17. var O, tag, result;
  18. return it === undefined ? 'Undefined' : it === null ? 'Null'
  19. // @@toStringTag case
  20. : typeof (tag = tryGet(O = $Object(it), TO_STRING_TAG)) == 'string' ? tag
  21. // builtinTag case
  22. : CORRECT_ARGUMENTS ? classofRaw(O)
  23. // ES3 arguments fallback
  24. : (result = classofRaw(O)) == 'Object' && isCallable(O.callee) ? 'Arguments' : result;
  25. };