Last active
August 29, 2015 14:14
-
-
Save jaycliff/a1840921ba1f1d114abc to your computer and use it in GitHub Desktop.
Douglas Crockford's typeOf and Jaycliff's innerTypeOf
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 typeOf(value) { | |
"use strict"; | |
var type = typeof value; | |
if (type === 'object') { | |
if (value) { | |
if (Object.prototype.toString.call(value) === '[object Array]') { | |
type = 'array'; | |
} | |
} else { | |
type = 'null'; | |
} | |
} | |
return type; | |
} | |
function innerTypeOf(arg) { | |
"use strict"; | |
return Object.prototype.toString.call(arg).slice(8, -1).toLowerCase(); | |
} | |
function innerTypeOf_complicated(arg) { | |
"use strict"; | |
return Object.prototype.toString.call(arg).match(innerTypeOf.regex)[1].toLowerCase(); | |
} | |
innerTypeOf.regex = /\s([a-zA-Z]+)/; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment