Created
October 31, 2012 03:38
-
-
Save zhuzhuaicoding/3984657 to your computer and use it in GitHub Desktop.
get type
This file contains hidden or 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 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