Copy codeThe Code is as follows:
Var is = function (obj, type ){
Var toString = Object. prototype. toString, undefined;
Return obj = null & type = 'null' |
Obj = undefined & type = 'undefined' |
ToString. call (obj). slice (8,-1) === type;
}
// Each logic and operation is enclosed in parentheses in the original text, but brackets can be omitted Based on the operator priority.
// The first line declares undefined. In my personal understanding, to improve performance, you do not have to query undefined in the top-level scope.
As explained in the ECMA-262, Object. prototype. toString () returns the type of the object instance in the format of "[Object", class, and "]" string.
Therefore, slice is used to extract the 'class' value, that is, the type value.
Among them, null and undefined are exceptions, because they return
[Object Object] in IE
Standard browser [object Window].
Therefore, let alone make a judgment.
Related Articles: javascript deep copy