Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function classof(subject) {
- const _type = typeof subject;
- if (_type.toLowerCase() !== 'object') {
- return _type;
- }
- if (subject === null) {
- return 'null';
- }
- if (Array.isArray(subject)) {
- return 'array';
- }
- // e.g. classof(new Object(null))
- if (!subject.constructor) {
- return 'object';
- }
- const className = subject.constructor.name;
- if (className.toLowerCase() === 'object') {
- return 'object';
- }
- return className;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement