Created
August 22, 2017 03:43
-
-
Save bpceee/d5b22fcef407a4d3d40e3b58fe0ab4c0 to your computer and use it in GitHub Desktop.
get real js type
This file contains 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 type(obj) { | |
var toString = Object.prototype.toString; | |
var map = { | |
'[object Boolean]' : 'boolean', | |
'[object Number]' : 'number', | |
'[object String]' : 'string', | |
'[object Function]' : 'function', | |
'[object Array]' : 'array', | |
'[object Date]' : 'date', | |
'[object RegExp]' : 'regExp', | |
'[object Undefined]': 'undefined', | |
'[object Null]' : 'null', | |
'[object Object]' : 'object' | |
}; | |
return map[toString.call(obj)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment