Created
November 8, 2011 07:34
-
-
Save abombss/1347229 to your computer and use it in GitHub Desktop.
Javascript Type / Class Name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTypeName(value) { | |
if (value === null) { | |
return "null"; | |
} | |
var t = typeof value; | |
switch (t) { | |
case "function": | |
case "object": | |
if (value.constructor && value.constructor.name) { | |
return value.constructor.name; | |
} else if (value.constructor) { | |
return value.constructor.toString().match(/\s([a-zA-Z]+)/)[1]; | |
} else { | |
return Object.prototype.toString.call(value); | |
} | |
default: | |
return t; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment