Copy Code code as follows:
/**
* Param:o indicates the value of the detection
* Return: Returns the string "undefined", "Number", "Boolean", "string", "function", "regexp", "array", "Date", "Error", "Object" or "null" "
*/
function TypeOf (o) {
var _tostring = Object.prototype.toString; Gets the object's ToString () method reference
Enumerating the basic data types and built-in object types, you can further supplement the array's detection data type range
var _type ={
"Undefined": "Undefined",
"Number": "Number",
"Boolean": "Boolean",
' String ': ' String ',
' [Object function] ': ' function ',
"[Object RegExp]": "RegExp",
"[Object Array]": "Array",
"[Object Date]": "Date",
"[Object Error]": "Error"
}
Return _type[typeof O] | | _type[_tostring.call (o)] | | (O?) "Object": "null"); Detect by converting a value to a string and then matching the return string to include a specific character
}
application Example:
var a = Math.Abs;
Alert (TypeOf (a)); Returns the string "function"
The code is very simple, the description is in the comments, here is not much nonsense, have the same needs of the small partners themselves to refer to the next bar