Created
May 31, 2017 18:12
-
-
Save localpcguy/b398d95cc90dd2b1a1474c27e5708c41 to your computer and use it in GitHub Desktop.
Get the class type of a JavaScript element
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 getClass(obj) { | |
if (typeof obj === 'undefined') { | |
return 'undefined'; | |
} | |
if (obj === null) { | |
return 'null'; | |
} | |
return Object.prototype.toString.call(obj).match(/^\[object\s(.*)\]$/)[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment