Skip to content

Instantly share code, notes, and snippets.

@bpceee
Created August 22, 2017 03:43
Show Gist options
  • Save bpceee/d5b22fcef407a4d3d40e3b58fe0ab4c0 to your computer and use it in GitHub Desktop.
Save bpceee/d5b22fcef407a4d3d40e3b58fe0ab4c0 to your computer and use it in GitHub Desktop.
get real js type
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