OK, first write about JS variable type of judgment bar, found in the study of code principles or debugging bugs in the process often encounter this problem, although there are many such examples on the Internet, or from their
own to write a collection bar, it is convenient to use.
1. First of all, needless to say, must be typeof, it is not a function, so the following parameters do not need parenthesis;
2.instanceof, to see that it has a meaning in itself, yes, look at the type of the function that it belongs to, but use
3.object.prototype.tostring.call (o) to determine whether the object is the target type. Object number]
when using the method tostring method, the [[Class]] property of the variable o
is obtained, and [[Class]] is an internal property, and all objects (native and host objects) have this property. [ [Class]] A string value that indicates the type of the object.
believe that the first two kinds of people will often encounter, the third may not be so easy to use, and so we understand the prototype prototype and call methods will feel that the same as the normal function calls;
In addition, we can encapsulate some of their own methods;
function GetType (o) {
var _t; return (_t = typeof (o)) = =
"Object"? O==null && "Null" | | Object.prototype.toString.call (o). Slice (8,-1): _t). toLowerCase ();