Skip to content

Instantly share code, notes, and snippets.

@abombss
Created November 8, 2011 07:34
Show Gist options
  • Save abombss/1347229 to your computer and use it in GitHub Desktop.
Save abombss/1347229 to your computer and use it in GitHub Desktop.
Javascript Type / Class Name
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