Skip to content

Instantly share code, notes, and snippets.

@zhuzhuaicoding
Created October 31, 2012 03:38
Show Gist options
  • Select an option

  • Save zhuzhuaicoding/3984657 to your computer and use it in GitHub Desktop.

Select an option

Save zhuzhuaicoding/3984657 to your computer and use it in GitHub Desktop.
get type
function is(o, type) {
type = String(type).toLowerCase();
return (type == "null" && o === null) ||
(type == typeof o) ||
(type == "object" && o === Object(o)) ||
(type == "array" && Array.isArray && Array.isArray(o)) ||
Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type;
}
is(function(){}, "object"); // true
is(function(){}, "function"); // true
is([], "object"); // true
is(new String("string"), "string"); // true
http://dmitry.baranovskiy.com/post/typeof-and-friends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment