Created
January 17, 2013 05:42
-
-
Save WebReflection/4553965 to your computer and use it in GitHub Desktop.
All JSON compatible (and incompatible thanks to "function") types in a simple cross platform function
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
var type = function (isArray, type){ | |
return function(object) { | |
type = typeof object; | |
return type === "object" ? ( | |
object ? ( | |
isArray(object) ? "array" : type | |
) : "null" | |
) : type; | |
}; | |
}(Array.isArray || function(Array, toString, array){ | |
array = toString.call([]); | |
return function(object) { | |
return ( | |
object instanceof Array || | |
toString.call(object) === array | |
); | |
} | |
}(Array, {}.toString)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to test above snippet: