In development, it is unavoidable to judge the object type, and to enumerate the common judgment methods:
1.typeof: Valid for function string number undifined Boolean object, note that the return value is a string.
But null, array detects an object.
2,instanceof: Used to detect whether the object is an instance of a particular class, the return value is a Boolean value, preferably with the typeof (typeof value is an object with the instanceof for further determination). The inheritance chain can also be used to determine whether an object has been inherited.
3 . Object. Constructor: Function,string,number,boolean,object,array can be detected. But null,undefined error.
4,Object.prototype.toString.call (object): can detect the above various types, but do not know whether you can detect the inheritance of those classes, and will not inherit.
Hope that the cattle people greatly answer, exchange.
Reference: http://www.nowamagic.net/librarys/veda/detail/1250
This article is from the "Echo and you take off" blog, please be sure to keep this source http://5052416.blog.51cto.com/5042416/1684752
JS judging the type of object