Skip to content

Instantly share code, notes, and snippets.

@jaycliff
Last active August 29, 2015 14:14
Show Gist options
  • Save jaycliff/a1840921ba1f1d114abc to your computer and use it in GitHub Desktop.
Save jaycliff/a1840921ba1f1d114abc to your computer and use it in GitHub Desktop.
Douglas Crockford's typeOf and Jaycliff's innerTypeOf
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