Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. function classof(subject) {
  2. const _type = typeof subject;
  3. if (_type.toLowerCase() !== 'object') {
  4. return _type;
  5. }
  6.  
  7. if (subject === null) {
  8. return 'null';
  9. }
  10.  
  11. if (Array.isArray(subject)) {
  12. return 'array';
  13. }
  14.  
  15. // e.g. classof(new Object(null))
  16. if (!subject.constructor) {
  17. return 'object';
  18. }
  19.  
  20. const className = subject.constructor.name;
  21. if (className.toLowerCase() === 'object') {
  22. return 'object';
  23. }
  24.  
  25. return className;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement